diff --git a/pkg/common/oras/authprovider/authprovider_test.go b/pkg/common/oras/authprovider/authprovider_test.go index 40d163070..98da91d51 100644 --- a/pkg/common/oras/authprovider/authprovider_test.go +++ b/pkg/common/oras/authprovider/authprovider_test.go @@ -21,6 +21,8 @@ import ( "path/filepath" "testing" "time" + + re "github.com/deislabs/ratify/errors" ) const ( @@ -60,6 +62,51 @@ func (ap *TestAuthProvider) Provide(_ context.Context, _ string) (AuthConfig, er }, nil } +// Checks for creation of defaultAuthProvider with invalid config input +func TestProvide_CreationOfAuthProvider_ExpectedResults(t *testing.T) { + var testProviderFactory defaultProviderFactory + tests := []struct { + name string + configMap map[string]interface{} + isNegative bool + expect error + }{ + { + name: "input type for unmarshal is unsupported", + configMap: map[string]interface{}{ + "key1": 1, + "key2": true, + "key3": make(chan int), + }, + isNegative: true, + expect: re.ErrorCodeConfigInvalid, + }, + { + name: "input type can not be transformed accordingly", + configMap: map[string]interface{}{ + "Name": 1, + }, + isNegative: true, + expect: re.ErrorCodeConfigInvalid, + }, + { + name: "successfully creation of authProvider", + configMap: map[string]interface{}{ + "Name": "sample", + "ConfigPath": "/tmp", + }, + isNegative: false, + expect: nil, + }, + } + for _, testCase := range tests { + _, err := testProviderFactory.Create(AuthProviderConfig(testCase.configMap)) + if testCase.isNegative != (err != nil) { + t.Errorf("Expected %v in case %v, but got %v", testCase.expect, testCase.name, err) + } + } +} + // Checks for correct credential resolution when external docker config // path is provided func TestProvide_ExternalDockerConfigPath_ExpectedResults(t *testing.T) {