aboutsummaryrefslogtreecommitdiffhomepage
path: root/replacer_test.go
diff options
context:
space:
mode:
authorMatthew Holt <[email protected]>2019-12-29 13:12:52 -0700
committerMatthew Holt <[email protected]>2019-12-29 13:12:52 -0700
commit95d944613bffce1cee3783568ae229e116168ba4 (patch)
tree8ccfe59b7852fbc1e937d62898cec52f92ee2c44 /replacer_test.go
parent2b33d9a5e5d1bd12d27bea2cfe8341fd1e5703b2 (diff)
downloadcaddy-95d944613bffce1cee3783568ae229e116168ba4.tar.gz
caddy-95d944613bffce1cee3783568ae229e116168ba4.zip
Export Replacer and use concrete type instead of interface
The interface was only making things difficult; a concrete pointer is probably best.
Diffstat (limited to 'replacer_test.go')
-rw-r--r--replacer_test.go90
1 files changed, 43 insertions, 47 deletions
diff --git a/replacer_test.go b/replacer_test.go
index 88e83f550..42e9ee1f7 100644
--- a/replacer_test.go
+++ b/replacer_test.go
@@ -132,7 +132,7 @@ func TestReplacerSet(t *testing.T) {
}
func TestReplacerReplaceKnown(t *testing.T) {
- rep := replacer{
+ rep := Replacer{
providers: []ReplacerFunc{
// split our possible vars to two functions (to test if both functions are called)
func(key string) (val string, ok bool) {
@@ -204,7 +204,7 @@ func TestReplacerReplaceKnown(t *testing.T) {
}
func TestReplacerDelete(t *testing.T) {
- rep := replacer{
+ rep := Replacer{
static: map[string]string{
"key1": "val1",
"key2": "val2",
@@ -264,59 +264,55 @@ func TestReplacerMap(t *testing.T) {
}
func TestReplacerNew(t *testing.T) {
- var tc = NewReplacer()
+ rep := NewReplacer()
- rep, ok := tc.(*replacer)
- if ok {
- if len(rep.providers) != 2 {
- t.Errorf("Expected providers length '%v' got length '%v'", 2, len(rep.providers))
- } else {
- // test if default global replacements are added as the first provider
- hostname, _ := os.Hostname()
- os.Setenv("CADDY_REPLACER_TEST", "envtest")
- defer os.Setenv("CADDY_REPLACER_TEST", "")
+ if len(rep.providers) != 2 {
+ t.Errorf("Expected providers length '%v' got length '%v'", 2, len(rep.providers))
+ } else {
+ // test if default global replacements are added as the first provider
+ hostname, _ := os.Hostname()
+ os.Setenv("CADDY_REPLACER_TEST", "envtest")
+ defer os.Setenv("CADDY_REPLACER_TEST", "")
- for _, tc := range []struct {
- variable string
- value string
- }{
- {
- variable: "system.hostname",
- value: hostname,
- },
- {
- variable: "system.slash",
- value: string(filepath.Separator),
- },
- {
- variable: "system.os",
- value: runtime.GOOS,
- },
- {
- variable: "system.arch",
- value: runtime.GOARCH,
- },
- {
- variable: "env.CADDY_REPLACER_TEST",
- value: "envtest",
- },
- } {
- if val, ok := rep.providers[0](tc.variable); ok {
- if val != tc.value {
- t.Errorf("Expected value '%s' for key '%s' got '%s'", tc.value, tc.variable, val)
- }
- } else {
- t.Errorf("Expected key '%s' to be recognized by first provider", tc.variable)
+ for _, tc := range []struct {
+ variable string
+ value string
+ }{
+ {
+ variable: "system.hostname",
+ value: hostname,
+ },
+ {
+ variable: "system.slash",
+ value: string(filepath.Separator),
+ },
+ {
+ variable: "system.os",
+ value: runtime.GOOS,
+ },
+ {
+ variable: "system.arch",
+ value: runtime.GOARCH,
+ },
+ {
+ variable: "env.CADDY_REPLACER_TEST",
+ value: "envtest",
+ },
+ } {
+ if val, ok := rep.providers[0](tc.variable); ok {
+ if val != tc.value {
+ t.Errorf("Expected value '%s' for key '%s' got '%s'", tc.value, tc.variable, val)
}
+ } else {
+ t.Errorf("Expected key '%s' to be recognized by first provider", tc.variable)
}
}
- } else {
- t.Errorf("Expected type of replacer %T got %T ", &replacer{}, tc)
}
+
}
-func testReplacer() replacer {
- return replacer{
+func testReplacer() Replacer {
+ return Replacer{
providers: make([]ReplacerFunc, 0),
static: make(map[string]string),
}