-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcaddyfile_test.go
More file actions
58 lines (54 loc) · 1.13 KB
/
Copy pathcaddyfile_test.go
File metadata and controls
58 lines (54 loc) · 1.13 KB
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
package parspackip
import (
"testing"
"github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
)
func TestUnmarshalCaddyfile(t *testing.T) {
tests := []struct {
name string
input string
wantErr bool
check func(*ParspackIPRange) error
}{
{
name: "minimal config",
input: `parspack`,
check: func(p *ParspackIPRange) error {
// Should parse without error
return nil
},
},
{
name: "full config",
input: `parspack {
interval 2h
timeout 30s
}`,
check: func(p *ParspackIPRange) error {
// Should parse without error
return nil
},
},
{
name: "invalid directive",
input: `parspack { invalid_option }`,
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
p := &ParspackIPRange{}
d := caddyfile.NewTestDispenser(tt.input)
err := p.UnmarshalCaddyfile(d)
if (err != nil) != tt.wantErr {
t.Errorf("UnmarshalCaddyfile() error = %v, wantErr %v", err, tt.wantErr)
return
}
if tt.check != nil && err == nil {
if err := tt.check(p); err != nil {
t.Errorf("check failed: %v", err)
}
}
})
}
}