-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add returnVal any param validation to chainReader GetLatestValue
- Loading branch information
Showing
4 changed files
with
90 additions
and
2 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package utils_test | ||
|
||
import ( | ||
"errors" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
"github.com/smartcontractkit/chainlink-relay/pkg/utils" | ||
) | ||
|
||
type ExampleStruct struct { | ||
Name string | ||
} | ||
|
||
func TestValidateStructPtr(t *testing.T) { | ||
testNum := 42 | ||
testCases := []struct { | ||
name string | ||
input interface{} | ||
expect error | ||
}{ | ||
{ | ||
name: "struct pointer", | ||
input: &ExampleStruct{"Bob"}, | ||
expect: nil, | ||
}, | ||
{ | ||
name: "struct", | ||
input: ExampleStruct{"Alice"}, | ||
expect: errors.New("value of type utils_test.ExampleStruct is not a non-nil struct pointer"), | ||
}, | ||
{ | ||
name: "nil struct pointer", | ||
input: (*ExampleStruct)(nil), | ||
expect: errors.New("value of type *utils_test.ExampleStruct is not a non-nil struct pointer"), | ||
}, | ||
{ | ||
name: "nil", | ||
input: nil, | ||
expect: errors.New("value of type <nil> is not a non-nil struct pointer"), | ||
}, | ||
{ | ||
name: "non struct pointer", | ||
input: &testNum, | ||
expect: errors.New("dereferenced value of type *int is not a valid struct"), | ||
}, | ||
{ | ||
name: "non struct type", | ||
input: testNum, | ||
expect: errors.New("value of type int is not a non-nil struct pointer"), | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
result := utils.ValidateStructPtr(tc.input) | ||
assert.Equal(t, tc.expect, result) | ||
}) | ||
} | ||
} |