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
|
// SPDX-License-Identifier: GPL-3.0-or-later
package plan
import (
"strings"
"testing"
"git.labunix.xyz/krino/internal/config"
"git.labunix.xyz/krino/internal/enumtest"
)
// TestEveryKindIsNamed: every Kind has its own display name and a JSON
// action name, and every config.ActionKind maps onto a Kind. Kind and
// ActionKind are iota blocks from 0, so the i-th constant is the value i.
func TestEveryKindIsNamed(t *testing.T) {
kinds, err := enumtest.Names("step.go", "Kind")
if err != nil {
t.Fatal(err)
}
seen := map[string]bool{}
for i, name := range kinds {
k := Kind(i)
if s := k.String(); strings.HasPrefix(s, "Kind(") || seen[s] {
t.Errorf("%s: String() = %q", name, s)
} else {
seen[s] = true
}
if actionNames[k] == "" {
t.Errorf("%s has no JSON action name", name)
}
}
actions, err := enumtest.Names("../config/dir.go", "ActionKind")
if err != nil {
t.Fatal(err)
}
for i, name := range actions {
func() {
defer func() {
if r := recover(); r != nil {
t.Errorf("config.%s has no plan.Kind: %v", name, r)
}
}()
stepKind(config.ActionKind(i))
}()
}
}
// TestEveryConflictPolicyIsPlanned: every config.Conflict value is resolved
// by its own branch; an unknown value panics instead of quietly planning as
// suffix (review cli F13). Conflict is an iota block from 0.
func TestEveryConflictPolicyIsPlanned(t *testing.T) {
policies, err := enumtest.Names("../config/settings.go", "Conflict")
if err != nil {
t.Fatal(err)
}
d := fakeDisk{exists: map[string]bool{"/r/b.pdf": true}}
for i, name := range policies {
func() {
defer func() {
if r := recover(); r != nil {
t.Errorf("config.%s is not planned: %v", name, r)
}
}()
resolveConflict(Move, config.Conflict(i), "/r/a.pdf", "/r/b.pdf", d, claimed{})
}()
}
defer func() {
if recover() == nil {
t.Error("an unknown conflict policy did not panic")
}
}()
resolveConflict(Move, config.Conflict(len(policies)), "/r/a.pdf", "/r/b.pdf", d, claimed{})
}
|