// List returns all the existing mask in the system. // 200 Success, 404 Not Found, 500 Internal func (maskHandle) List(c *web.Context) error { masks, err := mask.GetAll(c.SessionID, c.Ctx["DB"].(*db.DB), nil) if err != nil { if err == mask.ErrNotFound { err = web.ErrNotFound } return err } c.Respond(masks, http.StatusOK) return nil }
// TestAPIFailureMasks validates the failure of the api using a nil session. func TestAPIFailureMasks(t *testing.T) { const fixture = "basic.json" masks, db := setup(t, fixture) defer teardown(t, db) t.Log("Given the need to validate failure of API with bad session.") { t.Log("When giving a nil session") { err := mask.Upsert(tests.Context, nil, masks[0]) 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 = mask.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 = mask.GetByCollection(tests.Context, nil, masks[0].Collection) 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 = mask.GetByName(tests.Context, nil, masks[0].Collection, masks[0].Field) 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 = mask.GetLastHistoryByName(tests.Context, nil, masks[0].Collection, masks[0].Field) 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 = mask.Delete(tests.Context, nil, masks[0].Collection, masks[0].Field) 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) } } }
// TestGetMasks validates retrieval of all query mask records. func TestGetMasks(t *testing.T) { const fixture = "basic.json" masks, db := setup(t, fixture) defer teardown(t, db) t.Log("Given the need to retrieve a list of query masks.") { t.Log("\tWhen using fixture", fixture) { for _, msk := range masks { if err := mask.Upsert(tests.Context, db, msk); err != nil { t.Fatalf("\t%s\tShould be able to create a query mask : %s", tests.Failed, err) } t.Logf("\t%s\tShould be able to create a query mask.", tests.Success) } msks, err := mask.GetAll(tests.Context, db, nil) if err != nil { t.Fatalf("\t%s\tShould be able to retrieve the query masks : %v", tests.Failed, err) } t.Logf("\t%s\tShould be able to retrieve the query masks", tests.Success) var count int for _, msk := range msks { if msk.Collection == collection || (msk.Collection == "*" && msk.Field == "test") { count++ } } if count != len(masks) { t.Fatalf("\t%s\tShould have two query masks : %d", tests.Failed, count) } t.Logf("\t%s\tShould have two query masks.", tests.Success) } } }