From cdd11e8cc7fcbb0ee258a95a9d7ee451eb392991 Mon Sep 17 00:00:00 2001 From: Will Pimblett Date: Thu, 10 Nov 2016 02:41:54 +0000 Subject: [PATCH] Adjust opts, change string slices to interface slices to play nice with user input --- htmldoc/document.go | 8 ++++---- htmldoc/document_test.go | 2 +- htmltest/htmltest.go | 3 ++- htmltest/options.go | 10 +++++----- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/htmldoc/document.go b/htmldoc/document.go index c1dc510..872ef21 100644 --- a/htmldoc/document.go +++ b/htmldoc/document.go @@ -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 @@ -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 } } diff --git a/htmldoc/document_test.go b/htmldoc/document_test.go index 0ba66fa..d5fec80 100644 --- a/htmldoc/document_test.go +++ b/htmldoc/document_test.go @@ -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) } diff --git a/htmltest/htmltest.go b/htmltest/htmltest.go index 7ba4418..028d58e 100644 --- a/htmltest/htmltest.go +++ b/htmltest/htmltest.go @@ -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") } diff --git a/htmltest/options.go b/htmltest/options.go index 1fbf306..a969f6d 100644 --- a/htmltest/options.go +++ b/htmltest/options.go @@ -20,8 +20,8 @@ type Options struct { IgnoreAlt bool IgnoreDirectoryMissingTrailingSlash bool - IgnoreURLs []string - IgnoreDirs []string + IgnoreURLs []interface{} + IgnoreDirs []interface{} TestFilesConcurrently bool DocumentConcurrencyLimit int @@ -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, @@ -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 } }