Skip to content

Commit

Permalink
Update config.DefaultParams to return slice of strings instead of string
Browse files Browse the repository at this point in the history
  • Loading branch information
baskarap committed Sep 13, 2019
1 parent b5198c3 commit 70387e8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
7 changes: 4 additions & 3 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package config

import (
"strings"
"sync"

"github.com/afex/hystrix-go/hystrix"
Expand Down Expand Up @@ -95,7 +96,7 @@ func ConcurrentOpacityCheckingEnabled() bool {
return getConfig().enableConcurrentOpacityChecking
}

// DefaultParams returns string of default parameters which will be applied to all image request, following the existing contract
func DefaultParams() string {
return getConfig().defaultParams
// DefaultParams returns []string of default parameters (separated by semicolon) which will be applied to all image request, following the existing contract
func DefaultParams() []string {
return strings.Split(getConfig().defaultParams, ";")
}
23 changes: 19 additions & 4 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ func TestConfigCasesWithStringValues(t *testing.T) {
key: "log.level",
callFunc: LogLevel,
},
{
key: "defaultParams",
callFunc: DefaultParams,
},
}

for _, c := range cases {
Expand Down Expand Up @@ -67,3 +63,22 @@ func TestConfigCasesWithIntValues(t *testing.T) {

assert.Equal(t, 0, v.GetInt("nonexistingkey"))
}

func TestConfigCasesWithStringSliceValues(t *testing.T) {
v := Viper()
v.Set("defaultParams", "auto=compress")
Update()
cases := []struct {
key string
callFunc func() []string
}{
{
key: "defaultParams",
callFunc: DefaultParams,
},
}

for _, c := range cases {
assert.Equal(t, v.GetStringSlice(c.key), c.callFunc())
}
}

0 comments on commit 70387e8

Please sign in to comment.