aboutsummaryrefslogtreecommitdiffstats
path: root/reader
diff options
context:
space:
mode:
Diffstat (limited to 'reader')
-rw-r--r--reader/reader.go3
-rw-r--r--reader/reader_test.go13
2 files changed, 15 insertions, 1 deletions
diff --git a/reader/reader.go b/reader/reader.go
index 4b9c425..5ba40ae 100644
--- a/reader/reader.go
+++ b/reader/reader.go
@@ -178,6 +178,9 @@ func Extract(dm string, ssheet string) ExtractedData {
//GetTargetFiles finds all xlsx and xlsm files in directory.
func GetTargetFiles(path string) ([]string, error) {
+ if lastchar := path[len(path)-1:]; lastchar != string(filepath.Separator) {
+ return nil, fmt.Errorf("path must end in a %s character", string(filepath.Separator))
+ }
fullpath := strings.Join([]string{path, "*.xlsx"}, "")
output, err := filepath.Glob(fullpath)
if err != nil {
diff --git a/reader/reader_test.go b/reader/reader_test.go
index 33eea2e..4be02df 100644
--- a/reader/reader_test.go
+++ b/reader/reader_test.go
@@ -1,6 +1,7 @@
package reader
import (
+ "strings"
"testing"
)
@@ -137,8 +138,18 @@ func TestExtract(t *testing.T) {
func TestGetTargetFiles(t *testing.T) {
path := "/home/lemon/go/src/github.com/hammerheadlemon/datamaps-go/reader/testdata/"
- _, err := GetTargetFiles(path)
+ files, err := GetTargetFiles(path)
if err != nil {
t.Error(err)
}
+ found := false
+ for _, f := range files {
+ if strings.Contains(f, "test_template.xlsx") {
+ found = true
+ break
+ }
+ }
+ if found == false {
+ t.Errorf("test_template.xlsx not found - and it is there!")
+ }
}