This repository has been archived by the owner on Jul 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fetch_test.go
68 lines (58 loc) · 1.66 KB
/
fetch_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
package main
import (
"errors"
"testing"
gock "gopkg.in/h2non/gock.v1"
)
func TestFetchAvailabilityUnavailable(t *testing.T) {
defer gock.Off()
gock.New("http://www.apple.com").
Get("/jp/shop/retail/pickup-message").
Reply(200).
File("_fixtures/unavailable.json")
storeNames, err := FetchAvailability("MMEF2J/A")
if err != nil {
t.Errorf("Expected nil but got '%v'", err.Error())
}
Test{[]Store{}, storeNames}.DeepEqual(t)
}
func TestFetchAvailabilityAvailable(t *testing.T) {
defer gock.Off()
gock.New("http://www.apple.com").
Get("/jp/shop/retail/pickup-message").
Reply(200).
File("_fixtures/available.json")
storeNames, err := FetchAvailability("MMEF2J/A")
if err != nil {
t.Errorf("Expected nil but got '%v'", err.Error())
}
Test{[]Store{
{Name: "銀座", Product: "AirPods"},
{Name: "名古屋栄", Product: "AirPods"},
}, storeNames}.DeepEqual(t)
}
func TestFetchAvailabilityHTTPError(t *testing.T) {
defer gock.Off()
gock.New("http://www.apple.com").
Get("/jp/shop/retail/pickup-message").
ReplyError(errors.New("omg"))
storeNames, err := FetchAvailability("MMEF2J/A")
Test{
"Get http://www.apple.com/jp/shop/retail/pickup-message?location=100-0001&parts.0=MMEF2J%2FA: omg",
err.Error(),
}.Compare(t)
Test{[]Store{}, storeNames}.DeepEqual(t)
}
func TestFetchAvailabilityInvalidJSON(t *testing.T) {
defer gock.Off()
gock.New("http://www.apple.com").
Get("/jp/shop/retail/pickup-message").
Reply(200).
BodyString("{invalid}")
storeNames, err := FetchAvailability("MMEF2J/A")
Test{
"invalid character 'i' looking for beginning of object key string",
err.Error(),
}.Compare(t)
Test{[]Store{}, storeNames}.DeepEqual(t)
}