-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GBICSGO-1198: tests UpsertSinkComplianceCheck for ComplianceRepository
- Loading branch information
1 parent
0857df1
commit ecc9f49
Showing
1 changed file
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package repository | ||
|
||
import ( | ||
"context" | ||
"github.com/ottogroup/penelope/pkg/service" | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
) | ||
|
||
func TestComplianceRepository_UpsertSinkComplianceCheck_Twice(t *testing.T) { | ||
repository := setUpAndGetComplianceRepository(t) | ||
ctx := context.Background() | ||
|
||
sinkComplianceCheck := &SinkComplianceCheck{ | ||
ProjectSink: "test", | ||
} | ||
err := repository.UpsertSinkComplianceCheck(ctx, sinkComplianceCheck) | ||
assert.NoError(t, err) | ||
|
||
sinkComplianceCheck.Compliant = true | ||
err = repository.UpsertSinkComplianceCheck(ctx, sinkComplianceCheck) | ||
assert.NoError(t, err) | ||
|
||
_, err = repository.storageService.DB().Model(sinkComplianceCheck).WherePK().Delete() | ||
assert.NoError(t, err) | ||
} | ||
|
||
func TestComplianceRepository_UpsertSinkComplianceCheck_Reasons(t *testing.T) { | ||
repository := setUpAndGetComplianceRepository(t) | ||
ctx := context.Background() | ||
|
||
sinkComplianceCheck := &SinkComplianceCheck{ | ||
ProjectSink: "test", | ||
Compliant: false, | ||
Reasons: []string{"reason1", "reason2"}, | ||
} | ||
err := repository.UpsertSinkComplianceCheck(ctx, sinkComplianceCheck) | ||
assert.NoError(t, err) | ||
|
||
_, err = repository.storageService.DB().Model(sinkComplianceCheck).WherePK().Delete() | ||
assert.NoError(t, err) | ||
} | ||
|
||
func setUpAndGetComplianceRepository(t *testing.T) *defaultComplianceRepository { | ||
options := getTestConnectOptions() | ||
ctx := context.Background() | ||
|
||
storageService, err := service.NewStorageServiceWithConnectionOptions(ctx, options) | ||
assert.NoError(t, err) | ||
|
||
err = clearDatabase(storageService) | ||
assert.NoError(t, err) | ||
|
||
return &defaultComplianceRepository{storageService: storageService} | ||
} |