This repository has been archived by the owner on Mar 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathFactory_test.go
108 lines (88 loc) · 3.89 KB
/
Factory_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package connectsdk
import (
"reflect"
"testing"
"github.com/Ingenico-ePayments/connect-sdk-go/configuration"
"github.com/Ingenico-ePayments/connect-sdk-go/defaultimpl"
)
var apiKeyID = "someKey"
var secretAPIKey = "someSecret"
func TestCreateConfiguration(t *testing.T) {
defaultConfiguration := configuration.DefaultConfiguration(apiKeyID, secretAPIKey, "Test")
configuration, err := CreateConfiguration(apiKeyID, secretAPIKey, "Test")
if err != nil {
t.Fatalf("TestCreateConfiguration: %v", err)
}
if configuration.APIEndpoint != defaultConfiguration.APIEndpoint {
t.Fatalf("TestCreateConfiguration: APIEndpoint mismatch %v %v",
configuration.APIEndpoint, defaultConfiguration.APIEndpoint)
}
if configuration.AuthorizationType != defaultConfiguration.AuthorizationType {
t.Fatalf("TestCreateConfiguration: AuthorizationType mismatch %v %v",
configuration.AuthorizationType, defaultConfiguration.AuthorizationType)
}
if configuration.IdleTimeout != defaultConfiguration.IdleTimeout {
t.Fatalf("TestCreateConfiguration: IdleTimeout mismatch %v %v",
configuration.IdleTimeout, defaultConfiguration.IdleTimeout)
}
if configuration.ConnectTimeout != defaultConfiguration.ConnectTimeout {
t.Fatalf("TestCreateConfiguration: ConnectTimeout mismatch %v %v",
configuration.ConnectTimeout, defaultConfiguration.ConnectTimeout)
}
if configuration.SocketTimeout != defaultConfiguration.SocketTimeout {
t.Fatalf("TestCreateConfiguration: SocketTimeout mismatch %v %v",
configuration.SocketTimeout, defaultConfiguration.SocketTimeout)
}
if configuration.MaxConnections != defaultConfiguration.MaxConnections {
t.Fatalf("TestCreateConfiguration: MaxConnections mismatch %v %v",
configuration.MaxConnections, defaultConfiguration.MaxConnections)
}
if configuration.APIKeyID != apiKeyID {
t.Fatalf("TestCreateConfiguration: APIKeyID mismatch %v %v",
configuration.APIKeyID, apiKeyID)
}
if configuration.SecretAPIKey != secretAPIKey {
t.Fatalf("TestCreateConfiguration: SecretAPIKey mismatch %v %v",
configuration.SecretAPIKey, secretAPIKey)
}
}
func TestCreateCommunicator(t *testing.T) {
marshaller, _ := defaultimpl.NewDefaultMarshaller()
communicator, err := CreateCommunicator(apiKeyID, secretAPIKey, "Test")
if err != nil {
t.Fatalf("TestCreateCommunicator: %v", err)
}
if communicator.Marshaller() != marshaller {
t.Fatalf("TestCreateCommunicator: marshaller mismatch %v %v",
communicator.Marshaller(), marshaller)
}
session := communicator.Session()
connection := session.Connection()
if _, isDefaultConnection := connection.(*defaultimpl.DefaultConnection); !isDefaultConnection {
t.Fatalf("TestCreateCommunicator: connection type mismatch %T", connection)
}
authenticator := session.Authenticator()
if _, isDefaultAuthenticator := authenticator.(*defaultimpl.DefaultAuthenticator); !isDefaultAuthenticator {
t.Fatalf("TestCreateCommunicator: authenticator type mismatch %T", authenticator)
}
authAuthType := reflect.Indirect(reflect.ValueOf(authenticator)).FieldByName("authType").String()
if authAuthType != defaultimpl.V1HMAC {
t.Fatalf("TestCreateCommunicator: auth type mismatch %v", authAuthType)
}
authAPIKeyID := reflect.Indirect(reflect.ValueOf(authenticator)).FieldByName("apiKeyID").String()
if authAPIKeyID != apiKeyID {
t.Fatalf("TestCreateCommunicator: apiKeyID mismatch %v", authAPIKeyID)
}
authSecretAPIKey := reflect.Indirect(reflect.ValueOf(authenticator)).FieldByName("secretAPIKey").String()
if authSecretAPIKey != secretAPIKey {
t.Fatalf("TestCreateCommunicator: secretAPIKey mismatch %v", authSecretAPIKey)
}
metaDataProvider := session.MetaDataProvider()
headers := metaDataProvider.MetaDataHeaders()
if len(headers) != 1 {
t.Fatalf("TestCreateCommunicator: headers len mismatch %v", len(headers))
}
if headers[0].Name() != "X-GCS-ServerMetaInfo" {
t.Fatalf("TestCreateCommunicator: header name mismatch %v", headers[0].Name())
}
}