Skip to content
This repository has been archived by the owner on Jan 24, 2019. It is now read-only.

Commit

Permalink
Merge pull request #502 from talam/update_options_parsing
Browse files Browse the repository at this point in the history
options: update options parsing for better handling of incorrect values
  • Loading branch information
hlhendy authored Nov 20, 2017
2 parents a7c5d9c + e955d2b commit 6ddbb2c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
4 changes: 2 additions & 2 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ func (o *Options) Validate() error {
for _, u := range o.SkipAuthRegex {
CompiledRegex, err := regexp.Compile(u)
if err != nil {
msgs = append(msgs, fmt.Sprintf(
"error compiling regex=%q %s", u, err))
msgs = append(msgs, fmt.Sprintf("error compiling regex=%q %s", u, err))
continue
}
o.CompiledRegex = append(o.CompiledRegex, CompiledRegex)
}
Expand Down
21 changes: 21 additions & 0 deletions options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,18 @@ func TestProxyURLs(t *testing.T) {
assert.Equal(t, expected, o.proxyURLs)
}

func TestProxyURLsError(t *testing.T) {
o := testOptions()
o.Upstreams = append(o.Upstreams, "127.0.0.1:8081")
err := o.Validate()
assert.NotEqual(t, nil, err)

expected := errorMsg([]string{
"error parsing upstream: parse 127.0.0.1:8081: " +
"first path segment in URL cannot contain colon"})
assert.Equal(t, expected, err.Error())
}

func TestCompiledRegex(t *testing.T) {
o := testOptions()
regexps := []string{"/foo/.*", "/ba[rz]/quux"}
Expand All @@ -119,6 +131,15 @@ func TestCompiledRegexError(t *testing.T) {
"error compiling regex=\"barquux)\" error parsing regexp: " +
"unexpected ): `barquux)`"})
assert.Equal(t, expected, err.Error())

o.SkipAuthRegex = []string{"foobaz", "barquux)"}
err = o.Validate()
assert.NotEqual(t, nil, err)

expected = errorMsg([]string{
"error compiling regex=\"barquux)\" error parsing regexp: " +
"unexpected ): `barquux)`"})
assert.Equal(t, expected, err.Error())
}

func TestDefaultProviderApiSettings(t *testing.T) {
Expand Down

0 comments on commit 6ddbb2c

Please sign in to comment.