Skip to content

Commit 712a8b3

Browse files
authored
Check policy handles whitespace and comments ok (#788)
1 parent 72dff05 commit 712a8b3

1 file changed

Lines changed: 37 additions & 12 deletions

File tree

witness_policy_test.go

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,48 @@ import (
2020
)
2121

2222
func TestNewWitnessGroupFromPolicy(t *testing.T) {
23-
policy := `
23+
for _, test := range []struct {
24+
name string
25+
policy string
26+
}{
27+
{
28+
name: "tidy",
29+
policy: `
2430
witness w1 sigsum.org+e4ade967+AZuUY6B08pW3QVHu8uvsrxWPcAv9nykap2Nb4oxCee+r https://sigsum.org/witness/
2531
witness w2 example.com+3753d3de+AebBhMcghIUoavZpjuDofa4sW6fYHyVn7gvwDBfvkvuM https://example.com/witness/
2632
group g1 all w1 w2
2733
quorum g1
28-
`
29-
wg, err := NewWitnessGroupFromPolicy([]byte(policy))
30-
if err != nil {
31-
t.Fatalf("NewWitnessGroupFromPolicy() failed: %v", err)
32-
}
34+
`,
35+
}, {
36+
name: "whitespace and comments",
37+
policy: `
3338
34-
if wg.N != 2 {
35-
t.Errorf("Expected top-level group to have N=2, got %d", wg.N)
36-
}
37-
if len(wg.Components) != 2 {
38-
t.Fatalf("Expected top-level group to have 2 components, got %d", len(wg.Components))
39+
# comment
40+
witness w1 sigsum.org+e4ade967+AZuUY6B08pW3QVHu8uvsrxWPcAv9nykap2Nb4oxCee+r https://sigsum.org/witness/ #comment
41+
witness w2 example.com+3753d3de+AebBhMcghIUoavZpjuDofa4sW6fYHyVn7gvwDBfvkvuM https://example.com/witness/
42+
43+
44+
#comment
45+
group g1 all w1 w2
46+
47+
quorum g1
48+
`,
49+
},
50+
} {
51+
t.Run(test.name, func(t *testing.T) {
52+
53+
wg, err := NewWitnessGroupFromPolicy([]byte(test.policy))
54+
if err != nil {
55+
t.Fatalf("NewWitnessGroupFromPolicy() failed: %v", err)
56+
}
57+
58+
if wg.N != 2 {
59+
t.Errorf("Expected top-level group to have N=2, got %d", wg.N)
60+
}
61+
if len(wg.Components) != 2 {
62+
t.Fatalf("Expected top-level group to have 2 components, got %d", len(wg.Components))
63+
}
64+
})
3965
}
4066
}
4167

@@ -147,4 +173,3 @@ func TestNewWitnessGroupFromPolicy_Errors(t *testing.T) {
147173
})
148174
}
149175
}
150-

0 commit comments

Comments
 (0)