예제 #1
0
// TestUpsertDelete tests if we can add/remove a view to/from the db.
func TestUpsertDelete(t *testing.T) {
	views, db := setup(t)
	defer teardown(t, db)

	t.Log("Given the need to upsert and delete views.")
	{
		t.Log("\tWhen starting from an empty views collection")
		{

			//----------------------------------------------------------------------
			// Upsert the view.

			if err := view.Upsert(tests.Context, db, &views[0]); err != nil {
				t.Fatalf("\t%s\tShould be able to upsert a view : %s", tests.Failed, err)
			}
			t.Logf("\t%s\tShould be able to upsert a view.", tests.Success)

			//----------------------------------------------------------------------
			// Get the view.

			v, err := view.GetByName(tests.Context, db, views[0].Name)
			if err != nil {
				t.Fatalf("\t%s\tShould be able to get the view by name : %s", tests.Failed, err)
			}
			t.Logf("\t%s\tShould be able to get the view by name.", tests.Success)

			//----------------------------------------------------------------------
			// Check that we got the expected view.

			if !reflect.DeepEqual(views[0], *v) {
				t.Logf("\t%+v", views[0])
				t.Logf("\t%+v", v)
				t.Fatalf("\t%s\tShould be able to get back the same view.", tests.Failed)
			}
			t.Logf("\t%s\tShould be able to get back the same view.", tests.Success)

			//----------------------------------------------------------------------
			// Delete the view.

			if err := view.Delete(tests.Context, db, views[0].Name); err != nil {
				t.Fatalf("\t%s\tShould be able to delete the view : %s", tests.Failed, err)
			}
			t.Logf("\t%s\tShould be able to delete the view.", tests.Success)

			//----------------------------------------------------------------------
			// Get the view.

			_, err = view.GetByName(tests.Context, db, views[0].Name)
			if err == nil {
				t.Fatalf("\t%s\tShould generate an error when getting a view with the deleted name : %s", tests.Failed, err)
			}
			t.Logf("\t%s\tShould generate an error when getting a view with the deleted name.", tests.Success)
		}
	}
}
예제 #2
0
파일: view.go 프로젝트: coralproject/xenia
// Delete removes the specified View from the system.
// 200 Success, 400 Bad Request, 404 Not Found, 500 Internal
func (viewHandle) Delete(c *web.Context) error {
	if err := view.Delete(c.SessionID, c.Ctx["DB"].(*db.DB), c.Params["name"]); err != nil {
		if err == view.ErrNotFound {
			err = web.ErrNotFound
		}
		return err
	}

	c.Respond(nil, http.StatusNoContent)
	return nil
}