Skip to content

Commit

Permalink
updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
khareyash05 committed May 3, 2023
1 parent a3e0ce6 commit 1c6adb1
Showing 1 changed file with 46 additions and 58 deletions.
104 changes: 46 additions & 58 deletions pkg/token/manualtoken_test.go
Original file line number Diff line number Diff line change
@@ -1,86 +1,74 @@
package token

import (
"errors"
"testing"

"github.com/Azure/go-autorest/autorest/adal"
)

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)
}
})
}
Expand Down

0 comments on commit 1c6adb1

Please sign in to comment.