-
Notifications
You must be signed in to change notification settings - Fork 0
/
datastorefixpls_test.go
97 lines (78 loc) · 1.65 KB
/
datastorefixpls_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
package datastorefixpls
import (
"sort"
"testing"
"time"
"google.golang.org/appengine/datastore"
)
var now = time.Now()
func TestAddsTimeSuffix(t *testing.T) {
ps := []datastore.Property{
{Name: "Field.", Value: now},
}
expected := []datastore.Property{
{Name: "Field.", Value: now},
{Name: "Field.Time", Value: now},
}
ps = denormalize(ps)
if !equal(ps, expected) {
t.Fatal("expected slices to be equal")
}
}
func TestAddsDotSuffix(t *testing.T) {
ps := []datastore.Property{
{Name: "Field.Time", Value: now},
}
expected := []datastore.Property{
{Name: "Field.", Value: now},
{Name: "Field.Time", Value: now},
}
ps = denormalize(ps)
if !equal(ps, expected) {
t.Fatal("expected slices to be equal")
}
}
func TestDontAddDuplicates(t *testing.T) {
ps := []datastore.Property{
{Name: "Field.", Value: now},
{Name: "Field.Time", Value: now},
}
expected := []datastore.Property{
{Name: "Field.", Value: now},
{Name: "Field.Time", Value: now},
}
ps = denormalize(ps)
if !equal(ps, expected) {
t.Fatal("expected slices to be equal")
}
}
func TestEqualWithoutOrderWorks(t *testing.T) {
a := []datastore.Property{
{Name: "A", Value: now},
{Name: "B", Value: now},
}
b := []datastore.Property{
{Name: "B", Value: now},
{Name: "A", Value: now},
}
if !equal(a, b) {
t.Fatal("expected a and b to be equal")
}
}
func equal(a, b []datastore.Property) bool {
sort.Slice(a, func(i, j int) bool {
return a[i].Name > a[j].Name
})
sort.Slice(b, func(i, j int) bool {
return b[i].Name > b[j].Name
})
if len(a) != len(b) {
return false
}
for i, v := range a {
if v != b[i] {
return false
}
}
return true
}