WIP tests

trunk
vilmibm 2022-06-17 17:02:27 -05:00
parent db5f52f1fb
commit 1e0eb4d13f
1 changed files with 24 additions and 6 deletions

View File

@ -43,6 +43,7 @@ func TestUserRegister(t *testing.T) {
ts := []struct {
name string
req func() *http.Request
setup func(opts *config.Options) error
assert func(t *testing.T) error
wantErr *HTTPError
@ -57,15 +58,22 @@ func TestUserRegister(t *testing.T) {
})
},
assert: func(t *testing.T) error {
// TODO
// TODO ensure user count is still 1
return nil
},
wantErr: &HTTPError{Code: 403, Msg: "user already exists"},
},
// TODO
}
for _, tt := range ts {
t.Run(tt.name, func(t *testing.T) {
var req *http.Request
if tt.req == nil {
req, _ = http.NewRequest("GET", "", strings.NewReader(""))
} else {
req = tt.req()
}
teardown, err := db.Setup(opts)
if err != nil {
t.Fatalf("could not initialize DB: %s", err.Error())
@ -85,14 +93,26 @@ func TestUserRegister(t *testing.T) {
return
}
// TODO
api := &API{Opts: *opts}
ctx := &ReqCtx{Req: req}
_, err = api.InstanceInfo(ctx)
if tt.wantErr != nil && err != nil {
if !reflect.DeepEqual(tt.wantErr, err) {
t.Errorf("got unwanted error: %s", err.Error())
}
return
}
if tt.wantErr != nil && err == nil {
t.Errorf("expected error")
return
}
err = tt.assert(t)
if err != nil {
t.Fatal(err.Error())
return
}
})
}
}
@ -138,9 +158,7 @@ func TestInstanceInfo(t *testing.T) {
} else {
req = tt.req()
}
api := &API{
Opts: *opts,
}
api := &API{Opts: *opts}
ctx := &ReqCtx{Req: req}
resp, err := api.InstanceInfo(ctx)
if tt.wantErr != nil && err != nil {