// TestAPIFailureSet validates the failure of the api using a nil session. func TestAPIFailureSet(t *testing.T) { const fixture = "basic.json" set1, db := setup(t, fixture) defer teardown(t, db) qsName := prefix + "_unknown" t.Log("Given the need to validate failure of API with bad session.") { t.Log("When giving a nil session") { err := query.EnsureIndexes(tests.Context, nil, set1) if err == nil { t.Fatalf("\t%s\tShould be refused create by api with bad session", tests.Failed) } t.Logf("\t%s\tShould be refused create by api with bad session: %s", tests.Success, err) err = query.Upsert(tests.Context, nil, set1) if err == nil { t.Fatalf("\t%s\tShould be refused create by api with bad session", tests.Failed) } t.Logf("\t%s\tShould be refused create by api with bad session: %s", tests.Success, err) _, err = query.GetNames(tests.Context, nil) if err == nil { t.Fatalf("\t%s\tShould be refused get request by api with bad session", tests.Failed) } t.Logf("\t%s\tShould be refused get request by api with bad session: %s", tests.Success, err) _, err = query.GetAll(tests.Context, nil, nil) if err == nil { t.Fatalf("\t%s\tShould be refused get request by api with bad session", tests.Failed) } t.Logf("\t%s\tShould be refused get request by api with bad session: %s", tests.Success, err) _, err = query.GetByName(tests.Context, nil, qsName) if err == nil { t.Fatalf("\t%s\tShould be refused get request by api with bad session", tests.Failed) } t.Logf("\t%s\tShould be refused get request by api with bad session: %s", tests.Success, err) _, err = query.GetLastHistoryByName(tests.Context, nil, qsName) if err == nil { t.Fatalf("\t%s\tShould be refused get request by api with bad session", tests.Failed) } t.Logf("\t%s\tShould be refused get request by api with bad session: %s", tests.Success, err) err = query.Delete(tests.Context, nil, qsName) if err == nil { t.Fatalf("\t%s\tShould be refused delete by api with bad session", tests.Failed) } t.Logf("\t%s\tShould be refused delete by api with bad session: %s", tests.Success, err) } } }
// TestEnsureIndex validates indexes can be ensured. func TestEnsureIndex(t *testing.T) { const fixture = "basic.json" set1, db := setup(t, fixture) defer teardown(t, db) t.Log("Given the need to validate ensureing indexes.") { t.Log("\tWhen using fixture", fixture) { if err := query.EnsureIndexes(tests.Context, db, set1); err != nil { t.Fatalf("\t%s\tShould be able to ensure a query set index : %s", tests.Failed, err) } t.Logf("\t%s\tShould be able to ensure a query set index.", tests.Success) } } }
// EnsureIndexes makes sure indexes for the specified set exist. // 204 SuccessNoContent, 400 Bad Request, 404 Not Found, 500 Internal func (queryHandle) EnsureIndexes(c *web.Context) error { db := c.Ctx["DB"].(*db.DB) set, err := query.GetByName(c.SessionID, db, c.Params["name"]) if err != nil { if err == query.ErrNotFound { err = web.ErrNotFound } return err } if err := query.EnsureIndexes(c.SessionID, db, set); err != nil { return err } c.Respond(nil, http.StatusNoContent) return nil }