-
-
Notifications
You must be signed in to change notification settings - Fork 34
/
id_test.go
63 lines (59 loc) · 1.23 KB
/
id_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
package runn
import (
"slices"
"testing"
"github.com/google/go-cmp/cmp"
"github.com/samber/lo"
)
func TestGenerateIDsUsingPath(t *testing.T) {
tests := []struct {
paths []string
seedReversePaths []string
}{
{
[]string{"a.yml", "b.yml", "c.yml"},
[]string{"a.yml", "b.yml", "c.yml"},
},
{
[]string{"path/to/a.yml", "path/to/b.yml", "path/to/c.yml"},
[]string{"a.yml", "b.yml", "c.yml"},
},
{
[]string{"path/to/bb/a.yml", "path/to/aa/a.yml"},
[]string{"a.yml/bb", "a.yml/aa"},
},
{
[]string{"path/to/bb/a.yml", "../../path/to/aa/a.yml"},
[]string{"a.yml/bb", "a.yml/aa"},
},
}
for _, tt := range tests {
om := map[string]*operator{}
for _, p := range tt.paths {
om[p] = &operator{
bookPath: p,
}
}
ops := &operatorN{
om: om,
}
if err := ops.generateIDsUsingPath(); err != nil {
t.Fatal(err)
}
got := lo.Map(lo.Values(ops.om), func(item *operator, _ int) string {
return item.id
})
want := lo.Map(tt.seedReversePaths, func(item string, _ int) string {
id, err := generateID(item)
if err != nil {
t.Fatal(err)
}
return id
})
slices.Sort(got)
slices.Sort(want)
if diff := cmp.Diff(want, got); diff != "" {
t.Error(diff)
}
}
}