-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_test.go
126 lines (120 loc) · 2.57 KB
/
data_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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package legionhq
import (
"encoding/json"
"reflect"
"testing"
)
const darthVaderCommanderJSON = `{
"cardType": "unit",
"defense": "red",
"surges": [],
"speed": 1,
"wounds": 8,
"courage": -1,
"cardSubtype": "trooper",
"cardName": "Darth Vader",
"title": "Dark Lord of the Sith",
"isUnique": true,
"rank": "commander",
"cost": 190,
"faction": "empire",
"imageName": "Darth Vader.jpeg",
"keywords": [
"Deflect",
"Immune",
"Master of the Force",
"Relentless",
"Impact",
"Pierce"
],
"upgradeBar": ["force", "force", "force"],
"history": [
{
"date": "12 September 2019",
"description": "Cost reduced from 200 to 190 points."
}
],
"id": "at"
}`
func Test_GetData(t *testing.T) {
tests := []struct {
name string
wantErr bool
}{
{name: "get data", wantErr: false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := GetData()
if (err != nil) != tt.wantErr {
t.Errorf("GetData() error = %v, wantErr %v", err, tt.wantErr)
return
}
dataJSON, _ := json.Marshal(&got)
t.Log(string(dataJSON))
})
}
}
func Test_execCardsJS(t *testing.T) {
tests := []struct {
name string
wantLenGreaterThan int
wantErr bool
}{
{name: "data js", wantLenGreaterThan: 0, wantErr: false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := execCardsJS()
if (err != nil) != tt.wantErr {
t.Errorf("execCardsJS() error = %v, wantErr %v", err, tt.wantErr)
return
}
if len(got) <= tt.wantLenGreaterThan {
t.Errorf("execCardsJS() got = %v, want > %v", len(got), tt.wantLenGreaterThan)
}
})
}
}
func Test_jsonToCard(t *testing.T) {
type args struct {
cardJSON string
}
tests := []struct {
name string
args args
want Card
}{
{
name: "Darth Vader Commander",
args: struct{ cardJSON string }{cardJSON: darthVaderCommanderJSON},
want: Card{
ID: "at",
CardName: "Darth Vader",
CardType: "unit",
CardSubType: "trooper",
Cost: 190,
Faction: "empire",
IsUnique: true,
Keywords: []string{
"Deflect",
"Immune",
"Master of the Force",
"Relentless",
"Impact",
"Pierce",
},
Rank: "commander",
UpgradeBar: []string{"force", "force", "force"},
ImageLocation: "Darth Vader.jpeg",
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := jsonToCard(tt.args.cardJSON); !reflect.DeepEqual(got, tt.want) {
t.Errorf("jsonToCard() = %v, want %v", got, tt.want)
}
})
}
}