mirror of
https://github.com/rancher/steve.git
synced 2025-09-01 07:27:46 +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:
@@ -72,7 +72,7 @@ func TestNewListOptionIndexer(t *testing.T) {
|
||||
}
|
||||
})
|
||||
|
||||
loi, err := NewListOptionIndexer(fields, store, true)
|
||||
loi, err := NewListOptionIndexer(context.Background(), fields, store, true)
|
||||
assert.Nil(t, err)
|
||||
assert.NotNil(t, loi)
|
||||
}})
|
||||
@@ -93,7 +93,7 @@ func TestNewListOptionIndexer(t *testing.T) {
|
||||
}
|
||||
})
|
||||
|
||||
_, err := NewListOptionIndexer(fields, store, false)
|
||||
_, err := NewListOptionIndexer(context.Background(), fields, store, false)
|
||||
assert.NotNil(t, err)
|
||||
}})
|
||||
tests = append(tests, testCase{description: "NewListOptionIndexer() with error returned from Begin(), should return an error", test: func(t *testing.T) {
|
||||
@@ -122,7 +122,7 @@ func TestNewListOptionIndexer(t *testing.T) {
|
||||
|
||||
store.EXPECT().WithTransaction(gomock.Any(), true, gomock.Any()).Return(fmt.Errorf("error"))
|
||||
|
||||
_, err := NewListOptionIndexer(fields, store, false)
|
||||
_, err := NewListOptionIndexer(context.Background(), fields, store, false)
|
||||
assert.NotNil(t, err)
|
||||
}})
|
||||
tests = append(tests, testCase{description: "NewListOptionIndexer() with error from Exec() when creating fields table, should return an error", test: func(t *testing.T) {
|
||||
@@ -159,7 +159,7 @@ func TestNewListOptionIndexer(t *testing.T) {
|
||||
}
|
||||
})
|
||||
|
||||
_, err := NewListOptionIndexer(fields, store, true)
|
||||
_, err := NewListOptionIndexer(context.Background(), fields, store, true)
|
||||
assert.NotNil(t, err)
|
||||
}})
|
||||
tests = append(tests, testCase{description: "NewListOptionIndexer() with error from create-labels, should return an error", test: func(t *testing.T) {
|
||||
@@ -200,7 +200,7 @@ func TestNewListOptionIndexer(t *testing.T) {
|
||||
}
|
||||
})
|
||||
|
||||
_, err := NewListOptionIndexer(fields, store, true)
|
||||
_, err := NewListOptionIndexer(context.Background(), fields, store, true)
|
||||
assert.NotNil(t, err)
|
||||
}})
|
||||
tests = append(tests, testCase{description: "NewListOptionIndexer() with error from Commit(), should return an error", test: func(t *testing.T) {
|
||||
@@ -242,7 +242,7 @@ func TestNewListOptionIndexer(t *testing.T) {
|
||||
}
|
||||
})
|
||||
|
||||
_, err := NewListOptionIndexer(fields, store, true)
|
||||
_, err := NewListOptionIndexer(context.Background(), fields, store, true)
|
||||
assert.NotNil(t, err)
|
||||
}})
|
||||
|
||||
@@ -962,7 +962,7 @@ func TestListByOptions(t *testing.T) {
|
||||
store.EXPECT().ReadInt(rows).Return(len(test.expectedList.Items), nil)
|
||||
store.EXPECT().CloseStmt(stmt).Return(nil)
|
||||
}
|
||||
list, total, contToken, err := lii.executeQuery(context.TODO(), queryInfo)
|
||||
list, total, contToken, err := lii.executeQuery(context.Background(), queryInfo)
|
||||
if test.expectedErr == nil {
|
||||
assert.Nil(t, err)
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user