github.com/Axway/agent-sdk@v1.1.101/pkg/apic/provisioning/credentials_test.go (about) 1 package provisioning_test 2 3 import ( 4 "testing" 5 6 "github.com/Axway/agent-sdk/pkg/apic/provisioning" 7 "github.com/stretchr/testify/assert" 8 ) 9 10 func TestCredentialBuilder(t *testing.T) { 11 tests := []struct { 12 name string 13 username string 14 password string 15 key string 16 id string 17 secret string 18 other map[string]interface{} 19 }{ 20 { 21 name: "Build Basic Auth Credential", 22 username: "basic-user", 23 password: "basic-pass", 24 }, 25 { 26 name: "Build API Key Credential", 27 key: "api-key-data", 28 }, 29 { 30 name: "Build OAuth Credential", 31 id: "client-id", 32 }, 33 { 34 name: "Build OAuth Credential with Secret", 35 id: "client-id", 36 secret: "secret", 37 }, 38 { 39 name: "Build Other Credential", 40 other: map[string]interface{}{ 41 "data1": "data1", 42 "data2": "data2", 43 }, 44 }, 45 } 46 for _, tt := range tests { 47 t.Run(tt.name, func(t *testing.T) { 48 builder := provisioning.NewCredentialBuilder() 49 50 var cred provisioning.Credential 51 switch { 52 case tt.key != "": 53 cred = builder.SetAPIKey(tt.key) 54 case tt.username != "": 55 cred = builder.SetHTTPBasic(tt.username, tt.password) 56 case tt.id != "" && tt.secret != "": 57 cred = builder.SetOAuthIDAndSecret(tt.key, tt.secret) 58 case tt.id != "": 59 cred = builder.SetOAuthID(tt.key) 60 case tt.other != nil: 61 cred = builder.SetCredential(tt.other) 62 } 63 64 assert.NotNil(t, cred) 65 }) 66 } 67 }