Skip to content

Commit

Permalink
test(env): test the parsing of "url:..."
Browse files Browse the repository at this point in the history
  • Loading branch information
favonia committed Aug 19, 2023
1 parent d6accec commit 9749d96
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
4 changes: 2 additions & 2 deletions internal/config/env_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ func ReadProvider(ppfmt pp.PP, key, keyDeprecated string, field *provider.Provid
case val == "local":
*field = provider.NewLocal()
return true
case strings.HasPrefix(val, "custom.url:"):
url := strings.TrimSpace(strings.TrimPrefix(val, "custom.url:"))
case strings.HasPrefix(val, "url:"):
url := strings.TrimSpace(strings.TrimPrefix(val, "url:"))
*field = provider.NewCustom(url)
return true
case val == "none":
Expand Down
12 changes: 7 additions & 5 deletions internal/config/env_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ func TestReadProvider(t *testing.T) {
keyDeprecated := keyPrefix + "DEPRECATED"

var (
none provider.Provider
doh = provider.NewCloudflareDOH()
trace = provider.NewCloudflareTrace()
local = provider.NewLocal()
ipify = provider.NewIpify()
none provider.Provider
doh = provider.NewCloudflareDOH()
trace = provider.NewCloudflareTrace()
local = provider.NewLocal()
ipify = provider.NewIpify()
custom = provider.NewCustom("https://url.io")
)

for name, tc := range map[string]struct {
Expand Down Expand Up @@ -153,6 +154,7 @@ func TestReadProvider(t *testing.T) {
"cloudflare.doh": {true, " \tcloudflare.doh ", false, "", none, doh, true, nil},
"none": {true, " none ", false, "", trace, none, true, nil},
"local": {true, " local ", false, "", trace, local, true, nil},
"custom": {true, " url:https://url.io ", false, "", trace, custom, true, nil},
"ipify": {
true, " ipify ", false, "", trace, ipify, true,
func(m *mocks.MockPP) {
Expand Down

0 comments on commit 9749d96

Please sign in to comment.