forked from contentful-labs/contentful-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors_test.go
40 lines (33 loc) · 1022 Bytes
/
errors_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package contentful
import (
"fmt"
"net/http"
"net/http/httptest"
"testing"
"github.com/stretchr/testify/assert"
)
func TestNotFoundErrorResponse(t *testing.T) {
var err error
assert := assert.New(t)
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(404)
fmt.Fprintln(w, string(readTestData("error-notfound.json")))
})
// test server
server := httptest.NewServer(handler)
defer server.Close()
// cma client
cma = NewCMA(CMAToken)
cma.BaseURL = server.URL
// test space
_, err = cma.GetSpace("unknown-space-id")
assert.NotNil(err)
_, ok := err.(NotFoundError)
assert.Equal(true, ok)
notFoundError := err.(NotFoundError)
assert.Equal(404, notFoundError.APIError.res.StatusCode)
assert.Equal("request-id", notFoundError.APIError.err.RequestID)
assert.Equal("The resource could not be found.", notFoundError.APIError.err.Message)
assert.Equal("Error", notFoundError.APIError.err.Sys.Type)
assert.Equal("NotFound", notFoundError.APIError.err.Sys.ID)
}