// List returns all the existing views in the system. // 200 Success, 404 Not Found, 500 Internal func (viewHandle) List(c *web.Context) error { views, err := view.GetAll(c.SessionID, c.Ctx["DB"].(*db.DB)) if err != nil { if err == view.ErrNotFound { err = web.ErrNotFound } return err } c.Respond(views, http.StatusOK) return nil }
// TestGetAll tests if we can get all views from the db. func TestGetAll(t *testing.T) { views1, db := setup(t) defer teardown(t, db) t.Log("Given the need to get all the views in the database.") { t.Log("\tWhen starting from an empty views collection") { for _, v := range views1 { if err := view.Upsert(tests.Context, db, &v); err != nil { t.Fatalf("\t%s\tShould be able to upsert views : %s", tests.Failed, err) } } t.Logf("\t%s\tShould be able to upsert views.", tests.Success) views2, err := view.GetAll(tests.Context, db) if err != nil { t.Fatalf("\t%s\tShould be able to get all views : %s", tests.Failed, err) } t.Logf("\t%s\tShould be able to get all views.", tests.Success) var filteredViews []view.View for _, vw := range views2 { if vw.Name[0:len(prefix)] == prefix { filteredViews = append(filteredViews, vw) } } if !reflect.DeepEqual(views1, filteredViews) { t.Logf("\t%+v", views1) t.Logf("\t%+v", filteredViews) t.Fatalf("\t%s\tShould be able to get back the same views.", tests.Failed) } t.Logf("\t%s\tShould be able to get back the same views.", tests.Success) } } }