Beispiel #1
0
// TestAPIFailureRegexs validates the failure of the api using a nil session.
func TestAPIFailureRegexs(t *testing.T) {
	const fixture = "basic.json"
	rgx1, db := setup(t, fixture)
	defer teardown(t, db)

	rgxName := prefix + "_unknown"

	t.Log("Given the need to validate failure of API with bad session.")
	{
		t.Log("When giving a nil session")
		{
			err := regex.Upsert(tests.Context, nil, rgx1)
			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 = regex.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 = regex.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 = regex.GetByName(tests.Context, nil, rgxName)
			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 = regex.GetByNames(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 = regex.GetLastHistoryByName(tests.Context, nil, rgxName)
			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 = regex.Delete(tests.Context, nil, rgxName)
			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)
		}
	}
}
Beispiel #2
0
// List returns all the existing regex in the system.
// 200 Success, 404 Not Found, 500 Internal
func (regexHandle) List(c *web.Context) error {
	rgxs, err := regex.GetAll(c.SessionID, c.Ctx["DB"].(*db.DB), nil)
	if err != nil {
		if err == regex.ErrNotFound {
			err = web.ErrNotFound
		}
		return err
	}

	c.Respond(rgxs, http.StatusOK)
	return nil
}
Beispiel #3
0
// TestGetRegexs validates retrieval of all Regex records.
func TestGetRegexs(t *testing.T) {
	const fixture = "basic.json"
	rgx1, db := setup(t, fixture)
	defer teardown(t, db)

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

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

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

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

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