Beispiel #1
0
// TestUpsertCreateMask tests if we can create a query mask record in the db.
func TestUpsertCreateMask(t *testing.T) {
	const fixture = "basic.json"
	masks, db := setup(t, fixture)
	defer teardown(t, db)

	t.Log("Given the need to save a query mask into the database.")
	{
		t.Log("\tWhen using fixture", fixture)
		{
			if err := mask.Upsert(tests.Context, db, masks[0]); err != nil {
				t.Fatalf("\t%s\tShould be able to create a query mask : %s", tests.Failed, err)
			}
			t.Logf("\t%s\tShould be able to create a query mask.", tests.Success)

			if _, err := mask.GetLastHistoryByName(tests.Context, db, masks[0].Collection, masks[0].Field); err != nil {
				t.Fatalf("\t%s\tShould be able to retrieve the query mask from history: %s", tests.Failed, err)
			}
			t.Logf("\t%s\tShould be able to retrieve the query mask from history.", tests.Success)

			msk, err := mask.GetByName(tests.Context, db, masks[0].Collection, masks[0].Field)
			if err != nil {
				t.Fatalf("\t%s\tShould be able to retrieve the query mask : %s", tests.Failed, err)
			}
			t.Logf("\t%s\tShould be able to retrieve the query mask.", tests.Success)

			if !reflect.DeepEqual(masks[0], msk) {
				t.Logf("\t%+v", masks[0])
				t.Logf("\t%+v", msk)
				t.Errorf("\t%s\tShould be able to get back the same query mask values.", tests.Failed)
			} else {
				t.Logf("\t%s\tShould be able to get back the same query mask values.", tests.Success)
			}
		}
	}
}
Beispiel #2
0
// TestAPIFailureMasks validates the failure of the api using a nil session.
func TestAPIFailureMasks(t *testing.T) {
	const fixture = "basic.json"
	masks, db := setup(t, fixture)
	defer teardown(t, db)

	t.Log("Given the need to validate failure of API with bad session.")
	{
		t.Log("When giving a nil session")
		{
			err := mask.Upsert(tests.Context, nil, masks[0])
			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 = mask.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 = mask.GetByCollection(tests.Context, nil, masks[0].Collection)
			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 = mask.GetByName(tests.Context, nil, masks[0].Collection, masks[0].Field)
			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 = mask.GetLastHistoryByName(tests.Context, nil, masks[0].Collection, masks[0].Field)
			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 = mask.Delete(tests.Context, nil, masks[0].Collection, masks[0].Field)
			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 #3
0
// TestUpsertUpdateMask validates update operation of a given mask.
func TestUpsertUpdateMask(t *testing.T) {
	const fixture = "basic.json"
	masks, db := setup(t, fixture)
	defer teardown(t, db)

	t.Log("Given the need to update a mask into the database.")
	{
		t.Log("\tWhen using two masks")
		{
			if err := mask.Upsert(tests.Context, db, masks[0]); err != nil {
				t.Fatalf("\t%s\tShould be able to create a mask : %s", tests.Failed, err)
			}
			t.Logf("\t%s\tShould be able to create a mask.", tests.Success)

			masks[0].Type = mask.MaskAll

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

			if _, err := mask.GetLastHistoryByName(tests.Context, db, masks[0].Collection, masks[0].Field); err != nil {
				t.Fatalf("\t%s\tShould be able to retrieve the mask from history: %s", tests.Failed, err)
			}
			t.Logf("\t%s\tShould be able to retrieve the mask from history.", tests.Success)

			updMsk, err := mask.GetByName(tests.Context, db, masks[0].Collection, masks[0].Field)
			if err != nil {
				t.Fatalf("\t%s\tShould be able to retrieve a mask record: %s", tests.Failed, err)
			}
			t.Logf("\t%s\tShould be able to retrieve a mask record.", tests.Success)

			if updMsk.Type != masks[0].Type {
				t.Logf("\t%+v", updMsk.Type)
				t.Logf("\t%+v", masks[0].Type)
				t.Errorf("\t%s\tShould have an updated mask record.", tests.Failed)
			} else {
				t.Logf("\t%s\tShould have an updated mask record.", tests.Success)
			}
		}
	}
}