Skip to content

Commit

Permalink
Fix batch test
Browse files Browse the repository at this point in the history
  • Loading branch information
rkodev committed Feb 12, 2024
1 parent 1b70d47 commit 0bfbbe3
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions batch_request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package msgraphgocore

import (
"context"
"errors"
"fmt"
"net/http"
"net/http/httptest"
Expand Down Expand Up @@ -150,7 +151,7 @@ func TestHandlesHTTPError(t *testing.T) {
testServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(403)
fmt.Fprint(w, "")
fmt.Fprint(w, "{}")
}))
defer testServer.Close()

Expand All @@ -171,7 +172,14 @@ func TestHandlesHTTPError(t *testing.T) {
require.NoError(t, err)

_, err = batch.Send(context.Background(), reqAdapter)
assert.Equal(t, err.Error(), "content is empty")

var sampleError *internal.SampleError
switch {
case errors.As(err, &sampleError):
assert.Equal(t, "error status code received from the API", err.Error())
default:
assert.Fail(t, "error type is not as expected")
}

err = DeRegisterError(BatchRequestErrorRegistryKey)
require.NoError(t, err)
Expand Down

0 comments on commit 0bfbbe3

Please sign in to comment.