-
-
Notifications
You must be signed in to change notification settings - Fork 30
/
id_test.go
49 lines (47 loc) · 982 Bytes
/
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
package runn
import (
"testing"
)
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 {
var ops []*operator
for _, p := range tt.paths {
ops = append(ops, &operator{
bookPath: p,
})
}
if err := generateIDsUsingPath(ops); err != nil {
t.Fatal(err)
}
for i, o := range ops {
want, err := generateID(tt.seedReversePaths[i])
if err != nil {
t.Fatal(err)
}
if o.id != want {
t.Errorf("want %s, got %s", want, o.id)
}
}
}
}