diff --git a/pkg/token/manualtoken_test.go b/pkg/token/manualtoken_test.go index 7b7bbf14..5ab8fb2d 100644 --- a/pkg/token/manualtoken_test.go +++ b/pkg/token/manualtoken_test.go @@ -1,6 +1,7 @@ package token import ( + "errors" "testing" "github.com/Azure/go-autorest/autorest/adal" @@ -8,79 +9,66 @@ import ( func TestNewManualToken(t *testing.T) { testCases := []struct { - name string - oAuthConfig adal.OAuthConfig - clientID string - resourceID string - tenantID string - token *adal.Token - wantErr bool + name string + oAuthCfg adal.OAuthConfig + clientID string + resourceID string + tenantID string + token *adal.Token + wantErr error }{ { - name: "valid inputs", - oAuthConfig: adal.OAuthConfig{}, - clientID: "test-client-id", - resourceID: "test-resource-id", - tenantID: "test-tenant-id", - token: &adal.Token{AccessToken: "test-access-token"}, - wantErr: false, + name: "Valid input", + oAuthCfg: adal.OAuthConfig{}, + clientID: "clientID", + resourceID: "resourceID", + tenantID: "tenantID", + token: &adal.Token{}, + wantErr: nil, }, { - name: "nil token", - oAuthConfig: adal.OAuthConfig{}, - clientID: "test-client-id", - resourceID: "test-resource-id", - tenantID: "test-tenant-id", - token: nil, - wantErr: true, + name: "Nil token", + oAuthCfg: adal.OAuthConfig{}, + clientID: "clientID", + resourceID: "resourceID", + tenantID: "tenantID", + token: nil, + wantErr: errors.New("token cannot be nil"), }, { - name: "empty client ID", - oAuthConfig: adal.OAuthConfig{}, - clientID: "", - resourceID: "test-resource-id", - tenantID: "test-tenant-id", - token: &adal.Token{AccessToken: "test-access-token"}, - wantErr: true, + name: "Empty clientID", + oAuthCfg: adal.OAuthConfig{}, + clientID: "", + resourceID: "resourceID", + tenantID: "tenantID", + token: &adal.Token{}, + wantErr: errors.New("clientID cannot be empty"), }, { - name: "empty resource ID", - oAuthConfig: adal.OAuthConfig{}, - clientID: "test-client-id", - resourceID: "", - tenantID: "test-tenant-id", - token: &adal.Token{AccessToken: "test-access-token"}, - wantErr: true, + name: "Empty resourceID", + oAuthCfg: adal.OAuthConfig{}, + clientID: "clientID", + resourceID: "", + tenantID: "tenantID", + token: &adal.Token{}, + wantErr: errors.New("resourceID cannot be empty"), }, { - name: "empty tenant ID", - oAuthConfig: adal.OAuthConfig{}, - clientID: "test-client-id", - resourceID: "test-resource-id", - tenantID: "", - token: &adal.Token{AccessToken: "test-access-token"}, - wantErr: true, + name: "Empty tenantID", + oAuthCfg: adal.OAuthConfig{}, + clientID: "clientID", + resourceID: "resourceID", + tenantID: "", + token: &adal.Token{}, + wantErr: errors.New("tenantID cannot be empty"), }, } for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { - provider, err := newManualToken(tc.oAuthConfig, tc.clientID, tc.resourceID, tc.tenantID, tc.token) - - if tc.wantErr { - if err == nil { - t.Errorf("Expected error, but got nil") - } - if provider != nil { - t.Errorf("Expected provider to be nil") - } - } else { - if err != nil { - t.Errorf("Expected no error, but got %v", err) - } - if provider == nil { - t.Errorf("Expected provider to not be nil") - } + _, err := newManualToken(tc.oAuthCfg, tc.clientID, tc.resourceID, tc.tenantID, tc.token) + if err != nil && err.Error() != tc.wantErr.Error() { + t.Errorf("expected error %v, but got %v", tc.wantErr, err) } }) }