aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Lemon <lemon@matthewlemon.com>2020-08-04 21:14:23 +0100
committerMatthew Lemon <lemon@matthewlemon.com>2020-08-04 21:14:23 +0100
commit87ed8707ba13fa1d52f7bcd06b3c1a5f989be2cf (patch)
tree34f14340b2eb08f04ee5fb12892f42f789d5a124
parent4e476e7f55cfd3aaf38ccbf7541731998eec853a (diff)
getting there with testing the master output
-rw-r--r--pkg/datamaps/writer_test.go48
1 files changed, 37 insertions, 11 deletions
diff --git a/pkg/datamaps/writer_test.go b/pkg/datamaps/writer_test.go
index 2a54f55..7a689b5 100644
--- a/pkg/datamaps/writer_test.go
+++ b/pkg/datamaps/writer_test.go
@@ -11,8 +11,9 @@ import (
)
var (
- fileToColIdx = make(map[string]int)
- filesInMaster []string
+ // filesInMaster is a map of each filename from the header row of a master, mapped to its
+ // column number
+ filesInMaster = make(map[string]int)
)
func TestWriteMaster(t *testing.T) {
@@ -96,7 +97,7 @@ func TestWriteMaster(t *testing.T) {
}
got_s := strings.TrimSuffix(string(got), "\n")
if strings.Compare(got_s, test.value) != 0 {
- t.Errorf("we wanted %s but got %s", test.value, got_s)
+ t.Errorf("when testing the database, we expected %s but got %s", test.value, got_s)
}
}
@@ -122,11 +123,42 @@ func TestWriteMaster(t *testing.T) {
err = sh.ForEachRow(rowVisitorTest)
+ for _, tt := range tests {
+ got, err := masterLookup(sh, tt.key, tt.filename)
+ if err != nil {
+ t.Fatal("Problem calling masterLookup()")
+ }
+ if got != tt.value {
+ t.Errorf("when testing the master, we expected value %s for key %s in col %s - got %s",
+ tt.value, tt.key, tt.filename, got)
+ }
+ }
+}
+
+func masterLookup(sheet *xlsx.Sheet, key string, filename string) (string, error) {
+ var out string
+ if err := sheet.ForEachRow(func(r *xlsx.Row) error {
+ if r.GetCell(0).Value == key {
+ out = r.GetCell(filesInMaster[filename]).Value
+ return nil
+ }
+ return nil
+ }); err != nil {
+ return "", err
+ }
+ return out, nil
}
func cellVisitorTest(c *xlsx.Cell) error {
- filesInMaster = append(filesInMaster, c.Value)
- fileToColIdx[c.Value] = c.Row.GetCoordinate() // NOT RIGHT - GETTING INDEX FOR ROW
+ seen := make(map[string]struct{})
+ if _, ok := seen[c.Value]; !ok {
+ if c.Value != "" {
+ x, _ := c.GetCoordinates()
+ filesInMaster[c.Value] = x
+ }
+ seen[c.Value] = struct{}{}
+ }
+
return nil
}
@@ -138,11 +170,5 @@ func rowVisitorTest(r *xlsx.Row) error {
r.ForEachCell(cellVisitorTest)
return nil
}
- // var key string
- // key = r.GetCell(0).Value
- // for idx, fn := range filesInMaster {
- // // TODO
- // }
- fmt.Println(r)
return nil
}