Skip to content

Commit

Permalink
Adjust opts,
Browse files Browse the repository at this point in the history
change string slices to interface slices to play nice with user input
  • Loading branch information
wjdp committed Nov 10, 2016
1 parent cb81620 commit cdd11e8
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
8 changes: 4 additions & 4 deletions htmldoc/document.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ func (doc *Document) Parse() {
doc.HTMLNode = htmlNode
}

func DocumentsFromDir(path string, ignorePatterns []string) []Document {
func DocumentsFromDir(path string, ignorePatterns []interface{}) []Document {
// Nice proxy for recurseDir
return recurseDir(path, ignorePatterns, "")
}

func recurseDir(basePath string, ignorePatterns []string, dPath string) []Document {
func recurseDir(basePath string, ignorePatterns []interface{}, dPath string) []Document {
// Recursive function that returns all Document struts in a given
// os directory.
// basePath: the directory to scan
Expand Down Expand Up @@ -85,9 +85,9 @@ func recurseDir(basePath string, ignorePatterns []string, dPath string) []Docume
return documents
}

func isDirIgnored(ignorePatterns []string, dir string) bool {
func isDirIgnored(ignorePatterns []interface{}, dir string) bool {
for _, item := range ignorePatterns {
if strings.Contains(dir, item) {
if strings.Contains(dir, item.(string)) {
return true
}
}
Expand Down
2 changes: 1 addition & 1 deletion htmldoc/document_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func TestDocumentParse(t *testing.T) {

func TestDocumentsFromDir(t *testing.T) {
// it creates Document struts from an os directory
docs := DocumentsFromDir("fixtures/documents", []string{})
docs := DocumentsFromDir("fixtures/documents", []interface{}{})
// Fixtures dir has seven documents in various folders
assert.Equals(t, "document count", len(docs), 7)
}
3 changes: 2 additions & 1 deletion htmltest/htmltest.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ func Test(optsUser map[string]interface{}) *HtmlTest {
hT.documents = []htmldoc.Document{doc}
} else if hT.opts.DirectoryPath != "" {
// Directory mode
hT.documents = htmldoc.DocumentsFromDir(hT.opts.DirectoryPath, hT.opts.IgnoreDirs)
hT.documents = htmldoc.DocumentsFromDir(
hT.opts.DirectoryPath, hT.opts.IgnoreDirs)
} else {
panic("Neither file or directory path provided")
}
Expand Down
10 changes: 5 additions & 5 deletions htmltest/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ type Options struct {
IgnoreAlt bool
IgnoreDirectoryMissingTrailingSlash bool

IgnoreURLs []string
IgnoreDirs []string
IgnoreURLs []interface{}
IgnoreDirs []interface{}

TestFilesConcurrently bool
DocumentConcurrencyLimit int
Expand Down Expand Up @@ -56,8 +56,8 @@ func DefaultOptions() map[string]interface{} {
"IgnoreAlt": false,
"IgnoreDirectoryMissingTrailingSlash": false,

"IgnoreURLs": []string{"photos.smugmug.com", "photos.newtheatre.org.uk"},
"IgnoreDirs": []string{"lib"},
"IgnoreURLs": []interface{}{},
"IgnoreDirs": []interface{}{},

"TestFilesConcurrently": false,
"DocumentConcurrencyLimit": 128,
Expand Down Expand Up @@ -100,7 +100,7 @@ func InList(list []string, key string) bool {

func (opts *Options) IsURLIgnored(url string) bool {
for _, item := range opts.IgnoreURLs {
if strings.Contains(url, item) {
if strings.Contains(url, item.(string)) {
return true
}
}
Expand Down

0 comments on commit cdd11e8

Please sign in to comment.