Skip to content

Commit

Permalink
add context to unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mmetc committed Jun 10, 2024
1 parent 38b2b23 commit bff5142
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pkg/apiserver/apic_metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func TestAPICSendMetrics(t *testing.T) {

stop := make(chan bool)
httpmock.ZeroCallCounters()
go api.SendMetrics(stop)
go api.SendMetrics(context.TODO(), stop)
time.Sleep(tc.duration)
stop <- true

Expand Down
6 changes: 3 additions & 3 deletions pkg/apiserver/apic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ func TestAPICGetMetrics(t *testing.T) {
ExecX(context.Background())
}

foundMetrics, err := apiClient.GetMetrics()
foundMetrics, err := apiClient.GetMetrics(context.TODO())
require.NoError(t, err)

assert.Equal(t, tc.expectedMetric.Bouncers, foundMetrics.Bouncers)
Expand Down Expand Up @@ -917,7 +917,7 @@ func TestAPICPullTopBLCacheFirstCall(t *testing.T) {
require.NoError(t, err)

blocklistConfigItemName := "blocklist:blocklist1:last_pull"
lastPullTimestamp, err := api.dbClient.GetConfigItem(blocklistConfigItemName)
lastPullTimestamp, err := api.dbClient.GetConfigItem(context.TODO(), blocklistConfigItemName)
require.NoError(t, err)
assert.NotEqual(t, "", *lastPullTimestamp)

Expand All @@ -929,7 +929,7 @@ func TestAPICPullTopBLCacheFirstCall(t *testing.T) {

err = api.PullTop(false)
require.NoError(t, err)
secondLastPullTimestamp, err := api.dbClient.GetConfigItem(blocklistConfigItemName)
secondLastPullTimestamp, err := api.dbClient.GetConfigItem(context.TODO(), blocklistConfigItemName)
require.NoError(t, err)
assert.Equal(t, *lastPullTimestamp, *secondLastPullTimestamp)
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/apiserver/apiserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func ValidateMachine(t *testing.T, machineID string, config *csconfig.DatabaseCf
dbClient, err := database.NewClient(ctx, config)
require.NoError(t, err)

err = dbClient.ValidateMachine(machineID)
err = dbClient.ValidateMachine(context.TODO(), machineID)
require.NoError(t, err)
}

Expand All @@ -177,7 +177,7 @@ func GetMachineIP(t *testing.T, machineID string, config *csconfig.DatabaseCfg)
dbClient, err := database.NewClient(ctx, config)
require.NoError(t, err)

machines, err := dbClient.ListMachines()
machines, err := dbClient.ListMachines(context.TODO())
require.NoError(t, err)

for _, machine := range machines {
Expand Down Expand Up @@ -273,7 +273,7 @@ func CreateTestBouncer(t *testing.T, config *csconfig.DatabaseCfg) string {
apiKey, err := middlewares.GenerateAPIKey(keyLength)
require.NoError(t, err)

_, err = dbClient.CreateBouncer("test", "127.0.0.1", middlewares.HashSHA512(apiKey), types.ApiKeyAuthType)
_, err = dbClient.CreateBouncer(context.TODO(), "test", "127.0.0.1", middlewares.HashSHA512(apiKey), types.ApiKeyAuthType)
require.NoError(t, err)

return apiKey
Expand Down

0 comments on commit bff5142

Please sign in to comment.