-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient_test.go
87 lines (76 loc) · 2.21 KB
/
client_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
75
76
77
78
79
80
81
82
83
84
85
86
87
package psref
import (
"context"
"encoding/json"
"os"
"testing"
"time"
"github.com/stretchr/testify/require"
)
var (
debug = os.Getenv("PSREF_DEBUG") == "true"
testClient = NewClient(clientOptionFunc(func(c *Client) {
if debug {
c.debug = os.Stderr
}
}))
)
func testLogData(t testing.TB, v interface{}) {
if debug {
data, _ := json.MarshalIndent(v, "", "\t")
t.Logf("json:\n%s", string(data))
}
}
func TestProductTypes(t *testing.T) {
types, err := testClient.Products(context.Background())
require.NoError(t, err)
require.NotEmpty(t, types)
testLogData(t, types)
}
func TestWithdrawnProductTypes(t *testing.T) {
types, err := testClient.WithdrawnProducts(context.Background())
require.NoError(t, err)
require.NotEmpty(t, types)
testLogData(t, types)
}
func TestUpdates(t *testing.T) {
resp, err := testClient.Updates(context.Background())
require.NoError(t, err)
testLogData(t, resp)
t.Logf("%q", resp.VersionTitle)
t.Logf("Version = %v", resp.Version)
if !resp.VersionTS.IsZero() {
t.Logf("TS = %v", time.Since(resp.VersionTS).Round(time.Hour*24))
}
require.GreaterOrEqual(t, resp.Version, uint64(593))
require.Greater(t, len(resp.New)+len(resp.Updated)+len(resp.Withdrawn), 0)
require.NotZero(t, resp.VersionTS)
}
func TestProductByID(t *testing.T) {
p, err := testClient.ProductByID(context.Background(), 1234)
require.NoError(t, err)
require.Equal(t, "Lenovo_Legion_5P_15IMH05H", p.Key)
require.Greater(t, len(p.Models), 100)
testLogData(t, p)
}
func TestModelByID(t *testing.T) {
p, err := testClient.ModelByID(context.Background(), 1234, "82AW006JRK")
require.NoError(t, err)
require.Equal(t, "Lenovo_Legion_5P_15IMH05H", p.Key)
require.Greater(t, len(p.Detail), 30)
testLogData(t, p)
}
func TestModelByCode(t *testing.T) {
p, err := testClient.ModelByCode(context.Background(), "82AK0002US")
require.NoError(t, err)
require.Equal(t, "Lenovo_Flex_5G_14Q8CX05", p.Key)
require.Greater(t, len(p.Detail), 30)
testLogData(t, p)
}
func TestProductByModelCode(t *testing.T) {
p, err := testClient.ProductByModelCode(context.Background(), "82AK0002US")
require.NoError(t, err)
require.Equal(t, PID(1163), p.ID)
require.Equal(t, "Lenovo_Flex_5G_14Q8CX05", p.Key)
testLogData(t, p)
}