-
Notifications
You must be signed in to change notification settings - Fork 71
/
config_prefix_test.go
93 lines (86 loc) · 1.41 KB
/
config_prefix_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
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package main
import (
"fmt"
"reflect"
"testing"
"github.com/hashicorp/consul-template/config"
)
func TestPrefixConfig(t *testing.T) {
cases := []struct {
name string
s string
e *PrefixConfig
err bool
}{
{
"empty",
"",
nil,
true,
},
{
"empty_spaces",
" ",
nil,
true,
},
{
"missing_datacenter",
"foo",
nil,
true,
},
{
"prefix_source",
"foo@dc",
&PrefixConfig{
Datacenter: config.String("dc"),
Destination: config.String("foo"),
Source: config.String("foo"),
},
false,
},
{
"prefix_source_slash",
"/foo@dc",
&PrefixConfig{
Datacenter: config.String("dc"),
Destination: config.String("foo"),
Source: config.String("foo"),
},
false,
},
{
"prefix_destination",
"foo@dc:bar",
&PrefixConfig{
Datacenter: config.String("dc"),
Destination: config.String("bar"),
Source: config.String("foo"),
},
false,
},
{
"weird_characters",
"@*(#42",
nil,
true,
},
}
for i, tc := range cases {
t.Run(fmt.Sprintf("%d_%s", i, tc.name), func(t *testing.T) {
p, err := ParsePrefixConfig(tc.s)
if (err != nil) != tc.err {
t.Fatal(err)
}
if p != nil {
p.Dependency = nil
}
if !reflect.DeepEqual(tc.e, p) {
t.Errorf("\nexp: %#v\nact: %#v", tc.e, p)
}
})
}
}