-
Notifications
You must be signed in to change notification settings - Fork 583
Expand file tree
/
Copy patherrors_test.go
More file actions
30 lines (25 loc) · 1003 Bytes
/
errors_test.go
File metadata and controls
30 lines (25 loc) · 1003 Bytes
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
package testing
import (
"fmt"
"net/http"
"testing"
"github.com/gophercloud/gophercloud/v2"
th "github.com/gophercloud/gophercloud/v2/testhelper"
)
func TestErrUnexpectedResponseCode(t *testing.T) {
err := gophercloud.ErrUnexpectedResponseCode{
URL: "http://example.com",
Method: "GET",
Expected: []int{200},
Actual: 404,
Body: []byte("the response body"),
ResponseHeader: nil,
}
th.AssertEquals(t, err.GetStatusCode(), 404)
th.AssertEquals(t, gophercloud.ResponseCodeIs(err, http.StatusNotFound), true)
th.AssertEquals(t, gophercloud.ResponseCodeIs(err, http.StatusInternalServerError), false)
//even if application code wraps our error, ResponseCodeIs() should still work
errWrapped := fmt.Errorf("could not frobnicate the foobar: %w", err)
th.AssertEquals(t, gophercloud.ResponseCodeIs(errWrapped, http.StatusNotFound), true)
th.AssertEquals(t, gophercloud.ResponseCodeIs(errWrapped, http.StatusInternalServerError), false)
}