-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathitemavailability_test.go
65 lines (53 loc) · 1.51 KB
/
itemavailability_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
package schemaorg_test
import (
"testing"
"github.com/na4ma4/schemaorg"
)
func TestItemAvailabilityCompare(t *testing.T) {
t.Parallel()
itemList := []string{
"instock",
"INSTOCK",
"InStock",
"in stock",
" in stock ",
"https://schema.org/InStock",
"http://schema.org/InStock",
}
for _, e := range itemList {
if !schemaorg.InStock.Equals(e) {
t.Errorf("'%s' does not match %s", e, schemaorg.InStock)
}
}
if schemaorg.OnlineOnly.Equals("only") {
t.Errorf("'only' should not match %s", schemaorg.OnlineOnly)
}
if schemaorg.OnlineOnly.Equals("InStock") {
t.Errorf("'InStock' should not match %s", schemaorg.OnlineOnly)
}
}
func TestItemAvailabilityFromString(t *testing.T) {
t.Parallel()
itemList := map[string]schemaorg.ItemAvailability{
"instock": schemaorg.InStock,
"Discontinued": schemaorg.Discontinued,
"PreSale": schemaorg.PreSale,
"LimitedAvailability": schemaorg.LimitedAvailability,
"InStoreOnly": schemaorg.InStoreOnly,
"BackOrder": schemaorg.BackOrder,
"OnlineOnly": schemaorg.OnlineOnly,
"OutOfStock": schemaorg.OutOfStock,
"PreOrder": schemaorg.PreOrder,
"SoldOut": schemaorg.SoldOut,
}
for key, value := range itemList {
item, ok := schemaorg.ItemAvailabilityFromString(key)
if !ok {
t.Errorf("'%s' was not found", key)
}
if item != value {
t.Errorf("'%s' returned '%s' instead of '%s'", key, item, value)
}
t.Logf("'%s' returned '%s'", key, item)
}
}