-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi_test.go
52 lines (46 loc) · 1.01 KB
/
api_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
package currconv
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestNewAPI(t *testing.T) {
api := NewAPI(Config{
BaseURL: "baseURL",
APIKey: "APIKey",
Version: "Version",
})
assert.Equal(t, api.config.BaseURL, "baseURL")
assert.Equal(t, api.config.APIKey, "APIKey")
assert.Equal(t, api.config.Version, "Version")
}
func TestAPIError(t *testing.T) {
tests := []struct {
name string
baseURL string
errorMsg string
}{
{
"URL parse error",
"http://[::1]a",
"parse \"http://[::1]a\": invalid port \"a\" after host",
},
{
"HTTP Get error",
"/error/",
"Get \"/error/api/Version/convert?apiKey=APIKey&q=MYR_USD\": unsupported protocol scheme \"\"",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
api := NewAPI(Config{
BaseURL: tt.baseURL,
APIKey: "APIKey",
Version: "Version",
})
_, err := api.Convert(ConvertRequest{Q: []string{"MYR_USD"}})
if err != nil {
assert.EqualError(t, err, tt.errorMsg)
}
})
}
}