forked from getconversio/go-shopify
-
Notifications
You must be signed in to change notification settings - Fork 262
/
options_test.go
74 lines (63 loc) · 2.15 KB
/
options_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
69
70
71
72
73
74
package goshopify
import (
"fmt"
"net/http"
"testing"
"time"
)
func TestWithVersion(t *testing.T) {
c := MustNewClient(app, "fooshop", "abcd", WithVersion(testApiVersion))
expected := fmt.Sprintf("admin/api/%s", testApiVersion)
if c.pathPrefix != expected {
t.Errorf("WithVersion client.pathPrefix = %s, expected %s", c.pathPrefix, expected)
}
}
func TestWithVersionNoVersion(t *testing.T) {
c := MustNewClient(app, "fooshop", "abcd", WithVersion(""))
expected := "admin"
if c.pathPrefix != expected {
t.Errorf("WithVersion client.pathPrefix = %s, expected %s", c.pathPrefix, expected)
}
}
func TestWithoutVersionInInitiation(t *testing.T) {
c := MustNewClient(app, "fooshop", "abcd")
expected := "admin"
if c.pathPrefix != expected {
t.Errorf("WithVersion client.pathPrefix = %s, expected %s", c.pathPrefix, expected)
}
}
func TestWithVersionInvalidVersion(t *testing.T) {
c := MustNewClient(app, "fooshop", "abcd", WithVersion("9999-99b"))
expected := "admin"
if c.pathPrefix != expected {
t.Errorf("WithVersion client.pathPrefix = %s, expected %s", c.pathPrefix, expected)
}
}
func TestWithRetry(t *testing.T) {
c := MustNewClient(app, "fooshop", "abcd", WithRetry(5))
expected := 5
if c.retries != expected {
t.Errorf("WithRetry client.retries = %d, expected %d", c.retries, expected)
}
}
func TestWithLogger(t *testing.T) {
logger := &LeveledLogger{Level: LevelDebug}
c := MustNewClient(app, "fooshop", "abcd", WithLogger(logger))
if c.log != logger {
t.Errorf("WithLogger expected logs to match %v != %v", c.log, logger)
}
}
func TestWithUnstableVersion(t *testing.T) {
c := MustNewClient(app, "fooshop", "abcd", WithVersion(UnstableApiVersion))
expected := fmt.Sprintf("admin/api/%s", UnstableApiVersion)
if c.pathPrefix != expected {
t.Errorf("WithVersion client.pathPrefix = %s, expected %s", c.pathPrefix, expected)
}
}
func TestWithHTTPClient(t *testing.T) {
c := MustNewClient(app, "fooshop", "abcd", WithHTTPClient(&http.Client{Timeout: 30 * time.Second}))
expected := 30 * time.Second
if c.Client.Timeout.String() != expected.String() {
t.Errorf("WithVersion client.Client = %s, expected %s", c.Client.Timeout, expected)
}
}