Skip to content

Commit

Permalink
Fixing scenario in which using a non-existing file would return an er…
Browse files Browse the repository at this point in the history
…ror about schema
  • Loading branch information
stefanoj3 committed Oct 31, 2019
1 parent bb63327 commit 1512cad
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 4 additions & 3 deletions pkg/dictionary/dictionary.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@ import (
"io"
"net/http"
"os"
"strings"

"github.com/pkg/errors"
)

const commentPrefix = "#"

func NewDictionaryFrom(path string, doer Doer) ([]string, error) {
if _, err := os.Stat(path); !os.IsNotExist(err) {
return newDictionaryFromLocalFile(path)
if strings.HasPrefix(path, "http") {
return newDictionaryFromRemoteFile(path, doer)
}

return newDictionaryFromRemoteFile(path, doer)
return newDictionaryFromLocalFile(path)
}

func newDictionaryFromLocalFile(path string) ([]string, error) {
Expand Down
2 changes: 2 additions & 0 deletions pkg/dictionary/dictionary_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ func TestDictionaryFromFileWithInvalidPath(t *testing.T) {
d, err := dictionary.NewDictionaryFrom("testdata/gibberish_nonexisting_file", &http.Client{})
assert.Error(t, err)
assert.Nil(t, d)

assert.Contains(t, err.Error(), "unable to open")
}

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

0 comments on commit 1512cad

Please sign in to comment.