Exemplo n.º 1
0
// 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)
		}
	}
}
Exemplo n.º 2
0
// List returns all the existing Set names in the system.
// 200 Success, 404 Not Found, 500 Internal
func (queryHandle) List(c *web.Context) error {
	sets, err := query.GetAll(c.SessionID, c.Ctx["DB"].(*db.DB), nil)
	if err != nil {
		if err == query.ErrNotFound {
			err = web.ErrNotFound
		}
		return err
	}

	c.Respond(sets, http.StatusOK)
	return nil
}
Exemplo n.º 3
0
// TestGetSets validates retrieval of all Set records.
func TestGetSets(t *testing.T) {
	const fixture = "basic.json"
	set1, db := setup(t, fixture)
	defer teardown(t, db)

	t.Log("Given the need to retrieve a list of query sets.")
	{
		t.Log("\tWhen using fixture", fixture)
		{
			if err := query.Upsert(tests.Context, db, set1); err != nil {
				t.Fatalf("\t%s\tShould be able to create a query set : %s", tests.Failed, err)
			}
			t.Logf("\t%s\tShould be able to create a query set.", tests.Success)

			set1.Name += "2"
			if err := query.Upsert(tests.Context, db, set1); err != nil {
				t.Fatalf("\t%s\tShould be able to create a second query set : %s", tests.Failed, err)
			}
			t.Logf("\t%s\tShould be able to create a second query set.", tests.Success)

			sets, err := query.GetAll(tests.Context, db, nil)
			if err != nil {
				t.Fatalf("\t%s\tShould be able to retrieve the query sets : %v", tests.Failed, err)
			}
			t.Logf("\t%s\tShould be able to retrieve the query sets", tests.Success)

			var count int
			for _, set := range sets {
				if len(set.Name) > len(prefix) && set.Name[0:len(prefix)] == prefix {
					count++
				}
			}

			if count != 2 {
				t.Fatalf("\t%s\tShould have two query sets : %d", tests.Failed, count)
			}
			t.Logf("\t%s\tShould have two query sets.", tests.Success)
		}
	}
}