Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Authprovider test improvement #1170

Merged
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) {
junczhu marked this conversation as resolved.
Show resolved Hide resolved
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
Loading