mirror of
https://github.com/rancher/steve.git
synced 2025-09-01 15:37:31 +00:00
sql: propagate and use contexts (#465)
Previous SQLite-related code used context.Background() and context.TODO() because it was not developed with context awareness. This commit propagates the main Steve context so that it can be used when interacting with SQL context-aware functions. This PR removes all production-code use of context.Background() and context.TODO() and replaces test-code use of TODO with Background. Contributes to rancher/rancher#47825
This commit is contained in:
@@ -67,7 +67,7 @@ func TestQueryForRows(t *testing.T) {
|
||||
c := SetupMockConnection(t)
|
||||
client := SetupClient(t, c, nil, nil)
|
||||
s := NewMockStmt(gomock.NewController(t))
|
||||
ctx := context.TODO()
|
||||
ctx := context.Background()
|
||||
r := &sql.Rows{}
|
||||
s.EXPECT().QueryContext(ctx).Return(r, nil)
|
||||
rows, err := client.QueryForRows(ctx, s)
|
||||
@@ -79,7 +79,7 @@ func TestQueryForRows(t *testing.T) {
|
||||
c := SetupMockConnection(t)
|
||||
client := SetupClient(t, c, nil, nil)
|
||||
s := NewMockStmt(gomock.NewController(t))
|
||||
ctx := context.TODO()
|
||||
ctx := context.Background()
|
||||
s.EXPECT().QueryContext(ctx).Return(nil, fmt.Errorf("error"))
|
||||
_, err := client.QueryForRows(ctx, s)
|
||||
assert.NotNil(t, err)
|
||||
|
Reference in New Issue
Block a user