Skip to content

Commit

Permalink
context propagation: ValidateMachine()
Browse files Browse the repository at this point in the history
  • Loading branch information
mmetc committed Oct 3, 2024
1 parent c01daa4 commit 5ec02ae
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pkg/apiserver/alerts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func InitMachineTest(t *testing.T, ctx context.Context) (*gin.Engine, models.Wat

func LoginToTestAPI(t *testing.T, ctx context.Context, router *gin.Engine, config csconfig.Config) models.WatcherAuthResponse {
body := CreateTestMachine(t, ctx, router, "")
ValidateMachine(t, "test", config.API.Server.DbConfig)
ValidateMachine(t, ctx, "test", config.API.Server.DbConfig)

w := httptest.NewRecorder()
req, _ := http.NewRequestWithContext(ctx, http.MethodPost, "/v1/watchers/login", strings.NewReader(body))
Expand Down
4 changes: 1 addition & 3 deletions pkg/apiserver/apiserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,7 @@ func NewAPITestForwardedFor(t *testing.T, ctx context.Context) (*gin.Engine, csc
return router, config
}

func ValidateMachine(t *testing.T, machineID string, config *csconfig.DatabaseCfg) {
ctx := context.TODO()

func ValidateMachine(t *testing.T, ctx context.Context, machineID string, config *csconfig.DatabaseCfg) {
dbClient, err := database.NewClient(ctx, config)
require.NoError(t, err)

Expand Down
2 changes: 1 addition & 1 deletion pkg/apiserver/jwt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func TestLogin(t *testing.T) {
assert.Equal(t, `{"code":401,"message":"validation failure list:\npassword in body is required"}`, w.Body.String())

// Validate machine
ValidateMachine(t, "test", config.API.Server.DbConfig)
ValidateMachine(t, ctx, "test", config.API.Server.DbConfig)

// Login with invalid password
w = httptest.NewRecorder()
Expand Down

0 comments on commit 5ec02ae

Please sign in to comment.