-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfinanceapi_test.go
38 lines (28 loc) · 939 Bytes
/
financeapi_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
// Author(s): Michael Koeppl
package dinero
import (
"testing"
"github.com/stretchr/testify/assert"
)
const (
sourceCurrencyStr = "USD"
targetCurrencyStr = "EUR"
)
func TestMakeUrl(t *testing.T) {
url := URL(sourceCurrencyStr, targetCurrencyStr)
expectedResult := "http://rate-exchange-1.appspot.com/currency?from=USD&to=EUR"
assert.Equal(t, url, expectedResult, "Generated URL should match expected URL")
}
func TestCustomClient(t *testing.T) {
cc := customClient()
assert.Equal(t, cc.Timeout, timeout, "Set timeout of the custom client should be 5 seconds")
}
func TestQueryAPI(t *testing.T) {
res, _ := queryAPI(sourceCurrencyStr, targetCurrencyStr)
assert.NotEmpty(t, res, "Response must not be empty")
assert.NotZero(t, res.Rate, "Result rate must not be 0")
}
func TestRate(t *testing.T) {
r, _ := rate(sourceCurrencyStr, targetCurrencyStr)
assert.NotZero(t, r, "Exchange rate from response must not be 0")
}