forked from tildetown/bbj2
stuff
parent
2d22877f11
commit
89de893bf9
|
@ -71,12 +71,7 @@ func (a *API) Invoke(w http.ResponseWriter, req *http.Request, apiFn APIHandler)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx := ReqCtx{
|
resp, err := apiFn(&ReqCtx{*user, req})
|
||||||
User: *user,
|
|
||||||
Req: req,
|
|
||||||
}
|
|
||||||
|
|
||||||
resp, err := apiFn(&ctx)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
he := &HTTPError{}
|
he := &HTTPError{}
|
||||||
_ = errors.As(err, &he)
|
_ = errors.As(err, &he)
|
||||||
|
|
|
@ -43,14 +43,12 @@ func TestUserRegister(t *testing.T) {
|
||||||
|
|
||||||
ts := []struct {
|
ts := []struct {
|
||||||
name string
|
name string
|
||||||
opts config.Options
|
|
||||||
setup func(opts *config.Options) error
|
setup func(opts *config.Options) error
|
||||||
assert func(t *testing.T) error
|
assert func(t *testing.T) error
|
||||||
wantErr *HTTPError
|
wantErr *HTTPError
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "user already exists",
|
name: "user already exists",
|
||||||
opts: *opts,
|
|
||||||
setup: func(opts *config.Options) error {
|
setup: func(opts *config.Options) error {
|
||||||
return db.CreateUser(opts.DB, db.User{
|
return db.CreateUser(opts.DB, db.User{
|
||||||
Username: "albertwesker",
|
Username: "albertwesker",
|
||||||
|
@ -75,7 +73,13 @@ func TestUserRegister(t *testing.T) {
|
||||||
}
|
}
|
||||||
defer teardown()
|
defer teardown()
|
||||||
|
|
||||||
err = tt.setup(&tt.opts)
|
err = db.EnsureSchema(*opts)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("could not initialize DB: %s", err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err = tt.setup(opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("setup failed: %s", err.Error())
|
t.Fatalf("setup failed: %s", err.Error())
|
||||||
return
|
return
|
||||||
|
@ -100,22 +104,13 @@ func TestInstanceInfo(t *testing.T) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
teardown, err := db.Setup(opts)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("could not initialize DB: %s", err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
defer teardown()
|
|
||||||
|
|
||||||
ts := []struct {
|
ts := []struct {
|
||||||
name string
|
name string
|
||||||
opts config.Options
|
|
||||||
wantData instanceInfo
|
wantData instanceInfo
|
||||||
wantErr *HTTPError
|
wantErr *HTTPError
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "basic",
|
name: "basic",
|
||||||
opts: *opts,
|
|
||||||
wantData: instanceInfo{
|
wantData: instanceInfo{
|
||||||
InstanceName: "cool test zone",
|
InstanceName: "cool test zone",
|
||||||
AllowAnon: true,
|
AllowAnon: true,
|
||||||
|
@ -127,10 +122,10 @@ func TestInstanceInfo(t *testing.T) {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
req, _ := http.NewRequest("GET", "", strings.NewReader(""))
|
req, _ := http.NewRequest("GET", "", strings.NewReader(""))
|
||||||
api := &API{
|
api := &API{
|
||||||
Opts: tt.opts,
|
Opts: *opts,
|
||||||
Req: req,
|
|
||||||
}
|
}
|
||||||
resp, err := api.InstanceInfo()
|
ctx := &ReqCtx{Req: req}
|
||||||
|
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())
|
t.Errorf("got unwanted error: %s", err.Error())
|
||||||
return
|
return
|
||||||
|
|
|
@ -54,6 +54,7 @@ type Message struct {
|
||||||
func Setup(opts *config.Options) (func(), error) {
|
func Setup(opts *config.Options) (func(), error) {
|
||||||
db, err := sql.Open("sqlite3", opts.Config.DBPath)
|
db, err := sql.Open("sqlite3", opts.Config.DBPath)
|
||||||
opts.DB = db
|
opts.DB = db
|
||||||
|
// TODO consider inlining EnsureSchema here
|
||||||
return func() { db.Close() }, err
|
return func() { db.Close() }, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue