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