Skip to content

Commit

Permalink
test: Authprovider test improvement (#1170)
Browse files Browse the repository at this point in the history
  • Loading branch information
junczhu authored Nov 15, 2023
1 parent a47bdc6 commit f29794a
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions pkg/common/oras/authprovider/authprovider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"path/filepath"
"testing"
"time"

re "github.com/deislabs/ratify/errors"
)

const (
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit f29794a

Please sign in to comment.