-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
101 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
core/capabilities/ccip/oraclecreator/wrapped_oracle_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package oraclecreator | ||
|
||
import ( | ||
"errors" | ||
"io" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func Test_wrappedOracle_Close(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
oracleErr error | ||
closerErrors []error | ||
expectedErr error | ||
}{ | ||
{ | ||
name: "no errors", | ||
expectedErr: nil, | ||
}, | ||
{ | ||
name: "oracle error", | ||
oracleErr: err1, | ||
expectedErr: errors.New("close base oracle: err1"), | ||
}, | ||
{ | ||
name: "oracle and closers errors", | ||
oracleErr: err1, | ||
closerErrors: []error{err2, nil, err3}, | ||
expectedErr: errors.New("close base oracle: err1\nclose resource: err2\nclose resource: err3"), | ||
}, | ||
{ | ||
name: "closers only errors", | ||
oracleErr: nil, | ||
closerErrors: []error{err2, nil, err3}, | ||
expectedErr: errors.New("close resource: err2\nclose resource: err3"), | ||
}, | ||
{ | ||
name: "no errors with closers", | ||
closerErrors: []error{nil, nil, nil, nil}, | ||
expectedErr: nil, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
closers := make([]io.Closer, 0, len(tt.closerErrors)) | ||
for _, err := range tt.closerErrors { | ||
closers = append(closers, mockCloser{err: err}) | ||
} | ||
|
||
o := newWrappedOracle(mockOracle{err: tt.oracleErr}, closers) | ||
|
||
err := o.Close() | ||
if err == nil && tt.expectedErr == nil { | ||
assert.NoError(t, err) | ||
return | ||
} | ||
|
||
assert.Error(t, err) | ||
assert.Equal(t, tt.expectedErr.Error(), err.Error()) | ||
}) | ||
} | ||
} | ||
|
||
type mockCloser struct{ err error } | ||
|
||
func (m mockCloser) Close() error { return m.err } | ||
|
||
type mockOracle struct{ err error } | ||
|
||
func (m mockOracle) Close() error { return m.err } | ||
|
||
func (m mockOracle) Start() error { return m.err } | ||
|
||
var ( | ||
err1 = errors.New("err1") | ||
err2 = errors.New("err2") | ||
err3 = errors.New("err3") | ||
) |