forked from mattevans/dinero
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cache_test.go
41 lines (32 loc) · 968 Bytes
/
cache_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
package dinero
import (
"encoding/json"
"os"
"testing"
. "github.com/onsi/gomega"
)
// TestCache will test that our in-memory cache of forex results is working.
func TestCache(t *testing.T) {
// Register the test.
RegisterTestingT(t)
// Init dinero client.
client := NewClient(os.Getenv("OPEN_EXCHANGE_APP_ID"))
// Set a base currency to work with.
client.Rates.SetBaseCurrency("AUD")
// Get latest forex rates.
response1, err := client.Rates.All()
if err != nil {
t.Fatalf("Unexpected error running client.Rates.All(): %s", err.Error())
}
// Expire the cache
client.Cache.Expire("AUD")
// Fetch results again
response2, err := client.Rates.All()
if err != nil {
t.Fatalf("Unexpected error running client.Rates.All(): %s", err.Error())
}
// Compare the results, they shouldn't match, as update_at values will differ.
first, _ := json.Marshal(response1)
second, _ := json.Marshal(response2)
Expect(first).NotTo(MatchJSON(second))
}