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 41 42 43
|
package testing
import (
"testing"
"github.com/gophercloud/gophercloud"
th "github.com/gophercloud/gophercloud/testhelper"
)
func returnsUnexpectedResp(code int) gophercloud.ErrUnexpectedResponseCode {
return gophercloud.ErrUnexpectedResponseCode{
URL: "http://example.com",
Method: "GET",
Expected: []int{200},
Actual: code,
Body: nil,
ResponseHeader: nil,
}
}
func TestGetResponseCode404(t *testing.T) {
var err404 error = gophercloud.ErrDefault404{ErrUnexpectedResponseCode: returnsUnexpectedResp(404)}
err, ok := err404.(gophercloud.StatusCodeError)
th.AssertEquals(t, true, ok)
th.AssertEquals(t, err.GetStatusCode(), 404)
}
func TestGetResponseCode502(t *testing.T) {
var err502 error = gophercloud.ErrDefault502{ErrUnexpectedResponseCode: returnsUnexpectedResp(502)}
err, ok := err502.(gophercloud.StatusCodeError)
th.AssertEquals(t, true, ok)
th.AssertEquals(t, err.GetStatusCode(), 502)
}
func TestGetResponseCode504(t *testing.T) {
var err504 error = gophercloud.ErrDefault504{ErrUnexpectedResponseCode: returnsUnexpectedResp(504)}
err, ok := err504.(gophercloud.StatusCodeError)
th.AssertEquals(t, true, ok)
th.AssertEquals(t, err.GetStatusCode(), 504)
}
|