Skip to content

Commit

Permalink
Merge pull request #734 from MikelAlejoBR/RHCLOUD-36959-improve-tests…
Browse files Browse the repository at this point in the history
…-sources

RHCLOUD-36959 | fix: integration tests not passing
  • Loading branch information
MikelAlejoBR authored Jan 15, 2025
2 parents b3489ed + 6a82c60 commit be02f38
Show file tree
Hide file tree
Showing 18 changed files with 80 additions and 76 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ Here lies the source code for the Sources API re-write, based on the [original R
- `make lint` to run the same linters as the PR action, and print errors.
- Tests are currently in the same package adjacent to the source file. ex: `source_handlers.go` -> `source_handlers_test.go`, just using the standard library testing library. May change in the future.

### Launch the integration tests

In order to launch the integration tests just do the following:

- Launch a test database with the following command: `podman run --rm --name sources_test -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=postgres -e POSTGRES_DB=sources_api_test_go -p 5432:5432 --rm docker.io/postgres:13 postgres -c log_statement=all`
- Launch the tests themselves: `DATABASE_HOST=localhost DATABASE_PORT=5432 DATABASE_USER=postgres DATABASE_PASSWORD=postgres make alltest`

## License

This project is available as open source under the terms of the [Apache License 2.0](http://www.apache.org/licenses/LICENSE-2.0).
2 changes: 1 addition & 1 deletion application_authentication_handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ func TestApplicationAuthenticationDelete(t *testing.T) {

// Check that application authentication doesn't exist
_, err = appAuthDao.GetById(&appAuth.ID)
if !errors.Is(err, util.ErrNotFoundEmpty) {
if !errors.As(err, &util.ErrNotFound{}) {
t.Errorf("expected Not found error, got %s", err)
}

Expand Down
18 changes: 9 additions & 9 deletions application_handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1100,19 +1100,19 @@ func TestApplicationDelete(t *testing.T) {

// Check that application doesn't exist
_, err = applicationDao.GetById(&app.ID)
if !errors.Is(err, util.ErrNotFoundEmpty) {
if !errors.As(err, &util.ErrNotFound{}) {
t.Errorf("expected 'application not found', got %s", err)
}

// Check that authentication doesn't exist
_, err = authenticationDao.GetById(auth.ID)
if !errors.Is(err, util.ErrNotFoundEmpty) {
if !errors.As(err, &util.ErrNotFound{}) {
t.Errorf("expected 'authentication not found', got %s", err)
}

// Check that application authentication doesn't exist
_, err = appAuthDao.GetById(&appAuth.ID)
if !errors.Is(err, util.ErrNotFoundEmpty) {
if !errors.As(err, &util.ErrNotFound{}) {
t.Errorf("expected 'application authentication not found', got %s", err)
}

Expand Down Expand Up @@ -2185,19 +2185,19 @@ func TestApplicationDeleteWithOwnership(t *testing.T) {

applicationDao := dao.GetApplicationDao(suiteData.GetRequestParamsUserA())
_, err = applicationDao.GetById(&suiteData.ApplicationUserA().ID)
if !errors.Is(err, util.ErrNotFoundEmpty) {
if !errors.As(err, &util.ErrNotFound{}) {
t.Errorf("expected 'application not found', got %s", err)
}

authenticationDao := dao.GetAuthenticationDao(suiteData.GetRequestParamsUserA())
_, err = authenticationDao.GetById(suiteData.AuthenticationUserA().ID)
if !errors.Is(err, util.ErrNotFoundEmpty) {
if !errors.As(err, &util.ErrNotFound{}) {
t.Errorf("expected 'authentication not found', got %s", err)
}

applicationAuthenticationDao := dao.GetApplicationAuthenticationDao(suiteData.GetRequestParamsUserA())
_, err = applicationAuthenticationDao.GetById(&suiteData.ApplicationAuthenticationUserA().ID)
if !errors.Is(err, util.ErrNotFoundEmpty) {
if !errors.As(err, &util.ErrNotFound{}) {
t.Errorf("expected 'application authentication not found', got %s", err)
}

Expand Down Expand Up @@ -2232,19 +2232,19 @@ func TestApplicationDeleteWithOwnership(t *testing.T) {

applicationDao = dao.GetApplicationDao(suiteData.GetRequestParamsUserA())
_, err = applicationDao.GetById(&suiteData.ApplicationNoUser().ID)
if !errors.Is(err, util.ErrNotFoundEmpty) {
if !errors.As(err, &util.ErrNotFound{}) {
t.Errorf("expected 'application not found', got %s", err)
}

authenticationDao = dao.GetAuthenticationDao(suiteData.GetRequestParamsUserA())
_, err = authenticationDao.GetById(suiteData.AuthenticationNoUser().ID)
if !errors.Is(err, util.ErrNotFoundEmpty) {
if !errors.As(err, &util.ErrNotFound{}) {
t.Errorf("expected 'authentication not found', got %s", err)
}

applicationAuthenticationDao = dao.GetApplicationAuthenticationDao(suiteData.GetRequestParamsUserA())
_, err = applicationAuthenticationDao.GetById(&suiteData.ApplicationAuthenticationNoUser().ID)
if !errors.Is(err, util.ErrNotFoundEmpty) {
if !errors.As(err, &util.ErrNotFound{}) {
t.Errorf("expected 'application authentication not found', got %s", err)
}

Expand Down
2 changes: 1 addition & 1 deletion authentication_handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ func TestAuthenticationDelete(t *testing.T) {

// Check that the authentication is deleted
_, err = authenticationDao.GetById(uid)
if !errors.Is(err, util.ErrNotFoundEmpty) {
if !errors.As(err, &util.ErrNotFound{}) {
t.Errorf("expected 'authentication not found', got %s", err)
}

Expand Down
4 changes: 2 additions & 2 deletions dao/application_authentication_dao_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ func TestDeleteApplicationAuthenticationNotExists(t *testing.T) {
nonExistentId := int64(12345)
_, err := applicationAuthenticationDao.Delete(&nonExistentId)

if !errors.Is(err, util.ErrNotFoundEmpty) {
t.Errorf(`incorrect error returned. Want "%s", got "%s"`, util.ErrNotFoundEmpty, reflect.TypeOf(err))
if !errors.As(err, &util.ErrNotFound{}) {
t.Errorf(`incorrect error returned. Want "%s", got "%s"`, util.ErrNotFound{}, reflect.TypeOf(err))
}

DropSchema("delete")
Expand Down
6 changes: 3 additions & 3 deletions dao/application_dao_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ func TestDeleteApplicationNotExists(t *testing.T) {
nonExistentId := int64(12345)
_, err := applicationDao.Delete(&nonExistentId)

if !errors.Is(err, util.ErrNotFoundEmpty) {
t.Errorf(`incorrect error returned. Want "%s", got "%s"`, util.ErrNotFoundEmpty, reflect.TypeOf(err))
if !errors.As(err, &util.ErrNotFound{}) {
t.Errorf(`incorrect error returned. Want "%s", got "%s"`, util.ErrNotFound{}, reflect.TypeOf(err))
}

DropSchema("delete")
Expand Down Expand Up @@ -953,7 +953,7 @@ func TestApplicationCreateBadRequest(t *testing.T) {

// Create the test application.
err := applicationDao.Create(&application)
if !errors.Is(err, util.ErrBadRequestEmpty) {
if !errors.As(err, &util.ErrBadRequest{}) {
t.Errorf("wanted Bad Request err, got '%s'", err)
}

Expand Down
4 changes: 2 additions & 2 deletions dao/application_type_dao_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func TestApplicationTypeGetByNameNotFound(t *testing.T) {
t.Error("got application type object, want nil")
}

if !errors.Is(err, util.ErrNotFoundEmpty) {
if !errors.As(err, &util.ErrNotFound{}) {
t.Errorf("want not found err, got '%v'", err)
}

Expand All @@ -138,7 +138,7 @@ func TestApplicationTypeGetByNameBadRequest(t *testing.T) {
t.Error("got application type object, want nil")
}

if !errors.Is(err, util.ErrBadRequestEmpty) {
if !errors.As(err, &util.ErrBadRequest{}) {
t.Errorf("want bad request err, got '%v'", err)
}

Expand Down
24 changes: 12 additions & 12 deletions dao/authentication_db_dao_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,8 @@ func TestAuthenticationDbDelete(t *testing.T) {
}

_, err = dao.GetById(id)
if !errors.Is(err, util.ErrNotFoundEmpty) {
t.Errorf(`unexpected error received. Want "%s", got "%s"`, reflect.TypeOf(util.ErrNotFoundEmpty), reflect.TypeOf(err))
if !errors.As(err, &util.ErrNotFound{}) {
t.Errorf(`unexpected error received. Want "%s", got "%s"`, reflect.TypeOf(util.ErrNotFound{}), reflect.TypeOf(err))
}

DropSchema("authentications_db")
Expand All @@ -240,8 +240,8 @@ func TestAuthenticationDbDeleteNotFound(t *testing.T) {

dao := GetAuthenticationDao(&RequestParams{TenantID: &fixtures.TestTenantData[0].Id})
_, err := dao.Delete("12345")
if !errors.Is(err, util.ErrNotFoundEmpty) {
t.Errorf(`unexpected error received. Want "%s", got "%s"`, reflect.TypeOf(util.ErrNotFoundEmpty), reflect.TypeOf(err))
if !errors.As(err, &util.ErrNotFound{}) {
t.Errorf(`unexpected error received. Want "%s", got "%s"`, reflect.TypeOf(util.ErrNotFound{}), reflect.TypeOf(err))
}

DropSchema("authentications_db")
Expand Down Expand Up @@ -340,8 +340,8 @@ func TestListForSourceNotFound(t *testing.T) {
t.Errorf(`want error, got nil`)
}

if !errors.Is(err, util.ErrNotFoundEmpty) {
t.Errorf(`unexpected error received. Want "%s", got "%s"`, reflect.TypeOf(util.ErrNotFoundEmpty), reflect.TypeOf(err))
if !errors.As(err, &util.ErrNotFound{}) {
t.Errorf(`unexpected error received. Want "%s", got "%s"`, reflect.TypeOf(util.ErrNotFound{}), reflect.TypeOf(err))
}

DropSchema("authentications_db")
Expand Down Expand Up @@ -439,8 +439,8 @@ func TestListForApplicationNotFound(t *testing.T) {
t.Errorf(`want error, got nil`)
}

if !errors.Is(err, util.ErrNotFoundEmpty) {
t.Errorf(`unexpected error received. Want "%s", got "%s"`, reflect.TypeOf(util.ErrNotFoundEmpty), reflect.TypeOf(err))
if !errors.As(err, &util.ErrNotFound{}) {
t.Errorf(`unexpected error received. Want "%s", got "%s"`, reflect.TypeOf(util.ErrNotFound{}), reflect.TypeOf(err))
}

DropSchema("authentications_db")
Expand Down Expand Up @@ -546,8 +546,8 @@ func TestListForApplicationAuthenticationNotFound(t *testing.T) {
t.Errorf(`want error, got nil`)
}

if !errors.Is(err, util.ErrNotFoundEmpty) {
t.Errorf(`unexpected error received. Want "%s", got "%s"`, reflect.TypeOf(util.ErrNotFoundEmpty), reflect.TypeOf(err))
if !errors.As(err, &util.ErrNotFound{}) {
t.Errorf(`unexpected error received. Want "%s", got "%s"`, reflect.TypeOf(util.ErrNotFound{}), reflect.TypeOf(err))
}

DropSchema("authentications_db")
Expand Down Expand Up @@ -643,8 +643,8 @@ func TestListForEndpointNotFound(t *testing.T) {
t.Errorf(`want error, got nil`)
}

if !errors.Is(err, util.ErrNotFoundEmpty) {
t.Errorf(`unexpected error received. Want "%s", got "%s"`, reflect.TypeOf(util.ErrNotFoundEmpty), reflect.TypeOf(err))
if !errors.As(err, &util.ErrNotFound{}) {
t.Errorf(`unexpected error received. Want "%s", got "%s"`, reflect.TypeOf(util.ErrNotFound{}), reflect.TypeOf(err))
}

DropSchema("authentications_db")
Expand Down
4 changes: 2 additions & 2 deletions dao/endpoint_dao_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ func TestDeleteEndpointNotExists(t *testing.T) {
nonExistentId := int64(12345)
_, err := endpointDao.Delete(&nonExistentId)

if !errors.Is(err, util.ErrNotFoundEmpty) {
t.Errorf(`incorrect error returned. Want "%s", got "%s"`, util.ErrNotFoundEmpty, reflect.TypeOf(err))
if !errors.As(err, &util.ErrNotFound{}) {
t.Errorf(`incorrect error returned. Want "%s", got "%s"`, util.ErrNotFound{}, reflect.TypeOf(err))
}

DropSchema("delete")
Expand Down
12 changes: 6 additions & 6 deletions dao/rhc_connection_dao_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@ func TestRhcConnectionCreateSourceNotExists(t *testing.T) {
t.Errorf("want non nil error, got nil error")
}

if !errors.Is(err, util.ErrNotFoundEmpty) {
t.Errorf(`want "%s" type, got "%s"`, reflect.TypeOf(util.ErrNotFoundEmpty), reflect.TypeOf(err))
if !errors.As(err, &util.ErrNotFound{}) {
t.Errorf(`want "%s" type, got "%s"`, reflect.TypeOf(util.ErrNotFound{}), reflect.TypeOf(err))
}

DropSchema(RhcConnectionSchema)
Expand Down Expand Up @@ -273,8 +273,8 @@ func TestRhcConnectionDeleteNotFound(t *testing.T) {
t.Errorf(`want error, got nil`)
}

if !errors.Is(err, util.ErrNotFoundEmpty) {
t.Errorf(`want "%s" type, got "%s"`, reflect.TypeOf(util.ErrNotFoundEmpty), reflect.TypeOf(err))
if !errors.As(err, &util.ErrNotFound{}) {
t.Errorf(`want "%s" type, got "%s"`, reflect.TypeOf(util.ErrNotFound{}), reflect.TypeOf(err))
}

DropSchema(RhcConnectionSchema)
Expand Down Expand Up @@ -424,8 +424,8 @@ func TestDeleteRhcConnectionNotExists(t *testing.T) {
nonExistentId := int64(12345)
_, err := RhcConnectionDao.Delete(&nonExistentId)

if !errors.Is(err, util.ErrNotFoundEmpty) {
t.Errorf(`incorrect error returned. Want "%s", got "%s"`, util.ErrNotFoundEmpty, reflect.TypeOf(err))
if !errors.As(err, &util.ErrNotFound{}) {
t.Errorf(`incorrect error returned. Want "%s", got "%s"`, util.ErrNotFound{}, reflect.TypeOf(err))
}

DropSchema("delete")
Expand Down
16 changes: 8 additions & 8 deletions dao/source_dao_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -377,8 +377,8 @@ func TestDeleteSourceNotExists(t *testing.T) {
nonExistentId := int64(12345)
_, err := sourceDao.Delete(&nonExistentId)

if !errors.Is(err, util.ErrNotFoundEmpty) {
t.Errorf(`incorrect error returned. Want "%s", got "%s"`, util.ErrNotFoundEmpty, reflect.TypeOf(err))
if !errors.As(err, &util.ErrNotFound{}) {
t.Errorf(`incorrect error returned. Want "%s", got "%s"`, util.ErrNotFound{}, reflect.TypeOf(err))
}

DropSchema("delete")
Expand Down Expand Up @@ -492,7 +492,7 @@ func TestDeleteCascade(t *testing.T) {
}
id := deletedApplicationAuthentications[0].ID
_, err = applicationAuthenticationDao.GetById(&id)
if !errors.Is(err, util.ErrNotFoundEmpty) {
if !errors.As(err, &util.ErrNotFound{}) {
t.Errorf("Expected not found error, got %s", err)
}
}
Expand All @@ -504,7 +504,7 @@ func TestDeleteCascade(t *testing.T) {
}
id := deletedApplications[0].ID
_, err = applicationsDao.GetById(&id)
if !errors.Is(err, util.ErrNotFoundEmpty) {
if !errors.As(err, &util.ErrNotFound{}) {
t.Errorf("Expected not found error, got %s", err)
}
}
Expand All @@ -516,7 +516,7 @@ func TestDeleteCascade(t *testing.T) {
}
id := deletedEndpoints[0].ID
_, err = endpointDao.GetById(&id)
if !errors.Is(err, util.ErrNotFoundEmpty) {
if !errors.As(err, &util.ErrNotFound{}) {
t.Errorf("Expected not found error, got %s", err)
}
}
Expand All @@ -528,7 +528,7 @@ func TestDeleteCascade(t *testing.T) {
}
id := deletedRhcConnections[0].ID
_, err = rhcConnectionsDao.GetById(&id)
if !errors.Is(err, util.ErrNotFoundEmpty) {
if !errors.As(err, &util.ErrNotFound{}) {
t.Errorf("Expected not found error, got %s", err)
}
}
Expand All @@ -537,7 +537,7 @@ func TestDeleteCascade(t *testing.T) {
{
id := deletedSource.ID
_, err = sourceDao.GetById(&id)
if !errors.Is(err, util.ErrNotFoundEmpty) {
if !errors.As(err, &util.ErrNotFound{}) {
t.Errorf("Expected not found error, got %s", err)
}
}
Expand Down Expand Up @@ -569,7 +569,7 @@ func TestDeleteCascade(t *testing.T) {

// Check that the authentication is deleted
_, err = authenticationDao.GetById(id)
if !errors.Is(err, util.ErrNotFoundEmpty) {
if !errors.As(err, &util.ErrNotFound{}) {
t.Errorf("Expected not found error, got %s", err)
}

Expand Down
4 changes: 2 additions & 2 deletions dao/source_type_dao_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func TestSourceTypeGetByNameNotFound(t *testing.T) {
t.Error("got source type object, want nil")
}

if !errors.Is(err, util.ErrNotFoundEmpty) {
if !errors.As(err, &util.ErrNotFound{}) {
t.Errorf("want not found err, got '%v'", err)
}

Expand All @@ -92,7 +92,7 @@ func TestSourceTypeGetByNameBadRequest(t *testing.T) {
t.Error("got source type object, want nil")
}

if !errors.Is(err, util.ErrBadRequestEmpty) {
if !errors.As(err, &util.ErrBadRequest{}) {
t.Errorf("want bad request err, got '%v'", err)
}

Expand Down
8 changes: 4 additions & 4 deletions dao/tenant_dao_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,17 +223,17 @@ func TestTenantByIdentityNotFound(t *testing.T) {
AccountNumber: "invalid",
})

if !errors.Is(err, util.ErrNotFoundEmpty) {
t.Errorf(`unexpected error recevied. Want "%s", got "%s"`, reflect.TypeOf(util.ErrNotFoundEmpty), reflect.TypeOf(err))
if !errors.As(err, &util.ErrNotFound{}) {
t.Errorf(`unexpected error recevied. Want "%s", got "%s"`, reflect.TypeOf(util.ErrNotFound{}), reflect.TypeOf(err))
}

// Call the function under test by providing it an invalid orgId.
_, err = tenantDao.TenantByIdentity(&identity.Identity{
OrgID: "invalid",
})

if !errors.Is(err, util.ErrNotFoundEmpty) {
t.Errorf(`unexpected error recevied. Want "%s", got "%s"`, reflect.TypeOf(util.ErrNotFoundEmpty), reflect.TypeOf(err))
if !errors.As(err, &util.ErrNotFound{}) {
t.Errorf(`unexpected error recevied. Want "%s", got "%s"`, reflect.TypeOf(util.ErrNotFound{}), reflect.TypeOf(err))
}

DropSchema("tenant_tests")
Expand Down
4 changes: 2 additions & 2 deletions endpoint_handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1020,13 +1020,13 @@ func TestEndpointDelete(t *testing.T) {

// Check that endpoint doesn't exist
_, err = endpointDao.GetById(&endpoint.ID)
if !errors.Is(err, util.ErrNotFoundEmpty) {
if !errors.As(err, &util.ErrNotFound{}) {
t.Errorf("expected 'endpoint not found', got %s", err)
}

// Check that authentication doesn't exist
_, err = authenticationDao.GetById(auth.ID)
if !errors.Is(err, util.ErrNotFoundEmpty) {
if !errors.As(err, &util.ErrNotFound{}) {
t.Errorf("expected 'authentication not found', got %s", err)
}

Expand Down
2 changes: 1 addition & 1 deletion secret_handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,7 @@ func TestSecretDelete(t *testing.T) {

secretDao := dao.GetSecretDao(&dao.RequestParams{TenantID: &tenantIDForSecret, UserID: userID})
_, err = secretDao.GetById(&secret.DbID)
if !errors.Is(err, util.ErrNotFoundEmpty) {
if !errors.As(err, &util.ErrNotFound{}) {
t.Error("'secret not found' expected")
}
}
Expand Down
Loading

0 comments on commit be02f38

Please sign in to comment.