-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathvisa_test.go
More file actions
66 lines (56 loc) · 1.33 KB
/
Copy pathvisa_test.go
File metadata and controls
66 lines (56 loc) · 1.33 KB
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
package visa
import (
"encoding/base64"
"testing"
)
func TestSetConstants(t *testing.T) {
cases := []struct {
user_id, user_password string
}{
{"test_user_id", "dfjLRHzl4Mujn3aihy318OpySANPvO"},
}
for _, c := range cases {
setVariables(c.user_id, c.user_password)
if c.user_id != USER_ID && c.user_password != USER_PASSWORD {
t.Errorf("Setting of constants does not pass. Looking for %s, got %s", c.user_id, USER_ID)
}
}
}
func TestURL(t *testing.T) {
cases := []struct {
prodEnv bool
}{
{true},
{false},
}
for _, c := range cases {
testUrl := ""
getApiUrl(c.prodEnv)
switch c.prodEnv {
case true:
testUrl = "https://api.visa.com"
break
case false:
testUrl = "https://sandbox.api.visa.com"
break
}
if API_URL != testUrl {
t.Errorf("API url does not pass. Looking for %s, got %s", testUrl, API_URL)
}
}
}
func TestAuthHeader(t *testing.T) {
cases := []struct {
user_id, user_password string
}{
{"test_user_id", "dfjLRHzl4Mujn3aihy318OpySANPvO"},
}
for _, c := range cases {
testBase64 := base64.StdEncoding.EncodeToString([]byte(c.user_id + ":" + c.user_password))
setVariables(c.user_id, c.user_password)
authHeaderTest := createAuthHeader()
if authHeaderTest != testBase64 {
t.Errorf("Auth header does not pass. Looking for %s, got %s", testBase64, authHeaderTest)
}
}
}