aboutsummaryrefslogtreecommitdiff
path: root/internal/plan
diff options
context:
space:
mode:
Diffstat (limited to 'internal/plan')
-rw-r--r--internal/plan/conflict.go5
-rw-r--r--internal/plan/enum_test.go27
2 files changed, 31 insertions, 1 deletions
diff --git a/internal/plan/conflict.go b/internal/plan/conflict.go
index c4c6b64..c660a8b 100644
--- a/internal/plan/conflict.go
+++ b/internal/plan/conflict.go
@@ -120,10 +120,13 @@ func resolveConflict(kind Kind, policy config.Conflict, src, dst string, d Disk,
// displaces nothing.
resolved, skip := suffixed(dst, d, c)
return resolved, skip, ""
- default: // config.ConflictSuffix
+ case config.ConflictSuffix:
resolved, skip := suffixed(dst, d, c)
return resolved, skip, ""
}
+ // Every policy has its own branch (review cli F13): a new one must not
+ // quietly plan as another.
+ panic(fmt.Sprintf("plan: unknown config.Conflict %d", int(policy)))
}
// maxSuffixAttempts bounds suffixed(): it is unbounded by design and
diff --git a/internal/plan/enum_test.go b/internal/plan/enum_test.go
index 6458f5f..5e4f645 100644
--- a/internal/plan/enum_test.go
+++ b/internal/plan/enum_test.go
@@ -45,3 +45,30 @@ func TestEveryKindIsNamed(t *testing.T) {
}()
}
}
+
+// 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{})
+}