aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Lemon <y@yulqen.org>2024-04-20 16:42:06 +0100
committerMatthew Lemon <y@yulqen.org>2024-04-20 16:42:06 +0100
commited8a51dd320c5fb003f12003c7a66cfa353f6f81 (patch)
treed7a41ac466c53defaf7dd19364013432f366c666
parent04f78ef7a46ae4c4b8ab49153c16983c590783f5 (diff)
wip: testing the file package interface
-rw-r--r--cmd/dbasik-api/return.go36
-rw-r--r--cmd/dbasik-api/return_test.go13
2 files changed, 35 insertions, 14 deletions
diff --git a/cmd/dbasik-api/return.go b/cmd/dbasik-api/return.go
index 294c960..0973fc9 100644
--- a/cmd/dbasik-api/return.go
+++ b/cmd/dbasik-api/return.go
@@ -58,20 +58,6 @@ func NewReturn(name string, dm *Datamap, returnLines []ReturnLine) (*Return, err
}, nil
}
-//func cellVisitor(c *xlsx.Cell) error {
-// value, err := c.FormattedValue()
-// if err != nil {
-// fmt.Println(err.Error())
-// } else {
-// fmt.Printf("Sheet: %s, Cell value: %s\n", c.Row.Sheet.Name, value)
-// }
-// return err
-//}
-
-//func rowVisitor(r *xlsx.Row) error {
-// return r.ForEachCell(cellVisitor, xlsx.SkipEmptyCells)
-//}
-
func ParseXLSX(filePath string, dm *Datamap) (*Return, error) {
// Use tealeg/xlsx to parse the Excel file
wb, err := xlsx.OpenFile(filePath)
@@ -128,3 +114,25 @@ func contains(slice []string, str string) bool {
}
return false
}
+
+type FilePreparer interface {
+ Prepare(filePath string) error
+}
+
+type DirectoryFilePackage struct {
+ FilePath string
+}
+
+func (fp *DirectoryFilePackage) Prepare() ([]string, error) {
+ // return a slice of the files inside the directory pointed to by fh.FilePath
+ // and an error if any
+ files, err := filepath.Glob(fp.FilePath + "/*")
+ if err != nil {
+ return nil, err
+ }
+ return files, nil
+}
+
+func NewDirectoryFilePackage(filePath string) *DirectoryFilePackage {
+ return &DirectoryFilePackage{FilePath: filePath}
+}
diff --git a/cmd/dbasik-api/return_test.go b/cmd/dbasik-api/return_test.go
index c6a8664..bd2ffd9 100644
--- a/cmd/dbasik-api/return_test.go
+++ b/cmd/dbasik-api/return_test.go
@@ -2,6 +2,7 @@ package main
import (
"reflect"
+ "slices"
"testing"
"time"
)
@@ -166,3 +167,15 @@ func TestParseXLSX(t *testing.T) {
})
}
}
+
+func TestPrepareFiles(t *testing.T) {
+ fp := NewDirectoryFilePackage("../../testdata")
+ files, err := fp.Prepare()
+ if err != nil {
+ t.Error(err)
+ }
+ t.Log(files)
+ if !slices.Contains(files, "../../testdata/valid_excel.xlsx") {
+ t.Errorf("Prepare() did not return ../../testdata/valid_excel.xlsx")
+ }
+}