Skip to content

Commit

Permalink
Add canceled context test case
Browse files Browse the repository at this point in the history
  • Loading branch information
coffeefreak101 committed Nov 21, 2023
1 parent 3037c27 commit af946a8
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions bmc/boot_device_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,12 @@ func TestBootDeviceOverrideGet(t *testing.T) {
}

testCases := []struct {
name string
expectedErrorMsg string
expectedMetadata *Metadata
expectedOverride BootDeviceOverride
getters []interface{}
name string
hasCanceledContext bool
expectedErrorMsg string
expectedMetadata *Metadata
expectedOverride BootDeviceOverride
getters []interface{}
}{
{
name: "success",
Expand Down Expand Up @@ -212,11 +213,27 @@ func TestBootDeviceOverrideGet(t *testing.T) {
expectedErrorMsg: "no BootDeviceOverrideGetter implementations found",
getters: []interface{}{nil},
},
{
name: "with canceled context",
hasCanceledContext: true,
expectedMetadata: emptyMetadata,
expectedErrorMsg: "context canceled",
getters: []interface{}{
&mockBootDeviceOverrideGetter{},
},
},
}

for _, testCase := range testCases {
t.Run(testCase.name, func(t *testing.T) {
override, metadata, err := GetBootDeviceOverrideFromInterface(context.Background(), 0, testCase.getters)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

if testCase.hasCanceledContext {
cancel()
}

override, metadata, err := GetBootDeviceOverrideFromInterface(ctx, 0, testCase.getters)

if testCase.expectedErrorMsg != "" {
assert.ErrorContains(t, err, testCase.expectedErrorMsg)
Expand Down

0 comments on commit af946a8

Please sign in to comment.