bad method test
parent
89de893bf9
commit
db5f52f1fb
|
@ -106,6 +106,7 @@ func TestInstanceInfo(t *testing.T) {
|
||||||
|
|
||||||
ts := []struct {
|
ts := []struct {
|
||||||
name string
|
name string
|
||||||
|
req func() *http.Request
|
||||||
wantData instanceInfo
|
wantData instanceInfo
|
||||||
wantErr *HTTPError
|
wantErr *HTTPError
|
||||||
}{
|
}{
|
||||||
|
@ -117,19 +118,43 @@ func TestInstanceInfo(t *testing.T) {
|
||||||
Admins: []string{"jillValentine", "rebeccaChambers"},
|
Admins: []string{"jillValentine", "rebeccaChambers"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: "bad method",
|
||||||
|
req: func() *http.Request {
|
||||||
|
r, _ := http.NewRequest("POST", "", strings.NewReader(""))
|
||||||
|
return r
|
||||||
|
},
|
||||||
|
wantErr: &HTTPError{
|
||||||
|
Msg: "bad method",
|
||||||
|
Code: 400,
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
for _, tt := range ts {
|
for _, tt := range ts {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
req, _ := http.NewRequest("GET", "", strings.NewReader(""))
|
var req *http.Request
|
||||||
|
if tt.req == nil {
|
||||||
|
req, _ = http.NewRequest("GET", "", strings.NewReader(""))
|
||||||
|
} else {
|
||||||
|
req = tt.req()
|
||||||
|
}
|
||||||
api := &API{
|
api := &API{
|
||||||
Opts: *opts,
|
Opts: *opts,
|
||||||
}
|
}
|
||||||
ctx := &ReqCtx{Req: req}
|
ctx := &ReqCtx{Req: req}
|
||||||
resp, err := api.InstanceInfo(ctx)
|
resp, err := api.InstanceInfo(ctx)
|
||||||
if tt.wantErr != nil && err != nil {
|
if tt.wantErr != nil && err != nil {
|
||||||
t.Errorf("got unwanted error: %s", err.Error())
|
if !reflect.DeepEqual(tt.wantErr, err) {
|
||||||
|
t.Errorf("got unwanted error: %s", err.Error())
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if tt.wantErr != nil && err == nil {
|
||||||
|
t.Errorf("expected error")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
ii, ok := resp.Data.(instanceInfo)
|
ii, ok := resp.Data.(instanceInfo)
|
||||||
if !ok {
|
if !ok {
|
||||||
t.Errorf("could not cast data in %s", tt.name)
|
t.Errorf("could not cast data in %s", tt.name)
|
||||||
|
|
Loading…
Reference in New Issue