Skip to content

Commit dc9b574

Browse files
committed
test: create tests for parsing
1 parent 16cc268 commit dc9b574

1 file changed

Lines changed: 152 additions & 0 deletions

File tree

internal/geizhals/geizhals_test.go

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
package geizhals
2+
3+
import (
4+
"reflect"
5+
"testing"
6+
)
7+
8+
func Test_parseGeizhalsURL(t *testing.T) {
9+
type args struct {
10+
rawurl string
11+
entityType EntityType
12+
}
13+
tests := []struct {
14+
name string
15+
args args
16+
want EntityURL
17+
wantErr bool
18+
}{
19+
{
20+
name: "Wishlist URL DE",
21+
args: args{
22+
rawurl: "https://geizhals.de/?cat=WL-1156092&a=1",
23+
entityType: Wishlist,
24+
},
25+
want: EntityURL{
26+
SubmittedURL: "https://geizhals.de/?cat=WL-1156092&a=1",
27+
CleanURL: "https://geizhals.de/?cat=WL-1156092",
28+
Path: "?cat=WL-1156092",
29+
Location: "de",
30+
EntityID: -1156092,
31+
Type: Wishlist,
32+
},
33+
wantErr: false,
34+
},
35+
{
36+
name: "Wishlist URL AT",
37+
args: args{
38+
rawurl: "https://geizhals.at/?cat=WL-1156092",
39+
entityType: Wishlist,
40+
},
41+
want: EntityURL{
42+
SubmittedURL: "https://geizhals.at/?cat=WL-1156092",
43+
CleanURL: "https://geizhals.at/?cat=WL-1156092",
44+
Path: "?cat=WL-1156092",
45+
Location: "at",
46+
EntityID: -1156092,
47+
Type: Wishlist,
48+
},
49+
wantErr: false,
50+
},
51+
{
52+
name: "Wishlist URL UK",
53+
args: args{
54+
rawurl: "https://skinflint.co.uk/?cat=WL-1156092",
55+
entityType: Wishlist,
56+
},
57+
want: EntityURL{
58+
SubmittedURL: "https://skinflint.co.uk/?cat=WL-1156092",
59+
CleanURL: "https://skinflint.co.uk/?cat=WL-1156092",
60+
Path: "?cat=WL-1156092",
61+
Location: "uk",
62+
EntityID: -1156092,
63+
Type: Wishlist,
64+
},
65+
wantErr: false,
66+
},
67+
{
68+
name: "Product URL",
69+
args: args{
70+
rawurl: "https://geizhals.de/jabra-elite-85t-a2378831.html?hloc=pl",
71+
entityType: Product,
72+
},
73+
want: EntityURL{
74+
SubmittedURL: "https://geizhals.de/jabra-elite-85t-a2378831.html?hloc=pl",
75+
CleanURL: "https://geizhals.de/jabra-elite-85t-a2378831.html",
76+
Path: "jabra-elite-85t-a2378831.html",
77+
Location: "de",
78+
EntityID: 2378831,
79+
Type: Product,
80+
},
81+
wantErr: false,
82+
},
83+
{
84+
name: "Product URL Multiple",
85+
args: args{
86+
rawurl: "https://geizhals.de/jabra-elite-85t-a2378831.html?hloc=pl&hloc=de",
87+
entityType: Product,
88+
},
89+
want: EntityURL{
90+
SubmittedURL: "https://geizhals.de/jabra-elite-85t-a2378831.html?hloc=pl&hloc=de",
91+
CleanURL: "https://geizhals.de/jabra-elite-85t-a2378831.html",
92+
Path: "jabra-elite-85t-a2378831.html",
93+
Location: "de",
94+
EntityID: 2378831,
95+
Type: Product,
96+
},
97+
wantErr: false,
98+
},
99+
{
100+
name: "Product URL all",
101+
args: args{
102+
rawurl: "https://geizhals.de/jabra-elite-85t-a2378831.html?hloc=pl&hloc=de&hloc=at&hloc=uk",
103+
entityType: Product,
104+
},
105+
want: EntityURL{
106+
SubmittedURL: "https://geizhals.de/jabra-elite-85t-a2378831.html?hloc=pl&hloc=de&hloc=at&hloc=uk",
107+
CleanURL: "https://geizhals.de/jabra-elite-85t-a2378831.html",
108+
Path: "jabra-elite-85t-a2378831.html",
109+
Location: "de",
110+
EntityID: 2378831,
111+
Type: Product,
112+
},
113+
wantErr: false,
114+
},
115+
{
116+
name: "Product URL wrong hloc",
117+
args: args{
118+
rawurl: "https://geizhals.de/jabra-elite-85t-a2378831.html?hloc=fr",
119+
entityType: Product,
120+
},
121+
want: EntityURL{
122+
SubmittedURL: "https://geizhals.de/jabra-elite-85t-a2378831.html?hloc=fr",
123+
CleanURL: "https://geizhals.de/jabra-elite-85t-a2378831.html",
124+
Path: "jabra-elite-85t-a2378831.html",
125+
Location: "de",
126+
EntityID: 2378831,
127+
Type: Product,
128+
},
129+
},
130+
{
131+
name: "Product URL wrong hloc and TLD",
132+
args: args{
133+
rawurl: "https://geizhals.fr/jabra-elite-85t-a2378831.html?hloc=fr",
134+
entityType: Product,
135+
},
136+
want: EntityURL{},
137+
wantErr: true,
138+
},
139+
}
140+
for _, tt := range tests {
141+
t.Run(tt.name, func(t *testing.T) {
142+
got, err := parseGeizhalsURL(tt.args.rawurl)
143+
if (err != nil) != tt.wantErr {
144+
t.Errorf("parseGeizhalsURL() error = %v, wantErr %v", err, tt.wantErr)
145+
return
146+
}
147+
if !reflect.DeepEqual(got, tt.want) {
148+
t.Errorf("parseGeizhalsURL() got = %v, want %v", got, tt.want)
149+
}
150+
})
151+
}
152+
}

0 commit comments

Comments
 (0)