diff options
Diffstat (limited to '')
-rw-r--r-- | reader/reader.go | 9 | ||||
-rw-r--r-- | reader/reader_test.go | 15 |
2 files changed, 18 insertions, 6 deletions
diff --git a/reader/reader.go b/reader/reader.go index e4a6915..33e1773 100644 --- a/reader/reader.go +++ b/reader/reader.go @@ -2,6 +2,7 @@ package reader import ( "encoding/csv" + "errors" "fmt" "io" "io/ioutil" @@ -36,7 +37,7 @@ func ReadDML(path string) (*[]DatamapLine, error) { var s []DatamapLine data, err := ioutil.ReadFile(path) if err != nil { - return &s, &fileError{path, "Cannot open."} + return &s, errors.New("Cannot find file") } r := csv.NewReader(strings.NewReader(string(data))) for { @@ -45,7 +46,7 @@ func ReadDML(path string) (*[]DatamapLine, error) { break } if err != nil { - fmt.Printf("Cannot read line %s, ", err) + return &s, errors.New("Cannot read line %s") } if record[0] == "cell_key" { // this must be the header @@ -56,10 +57,6 @@ func ReadDML(path string) (*[]DatamapLine, error) { Sheet: strings.Trim(record[1], " "), Cellref: strings.Trim(record[2], " ")} s = append(s, dml) - // fmt.Printf("Key: %s; sheet: %s cellref: %s\n", dml.Key, dml.Sheet, dml.Cellref) - // klen, slen := Keylens(dml) - // fmt.Printf("Key length: %d\n", klen) - // fmt.Printf("Sheet length: %d\n\n", slen) } return &s, nil } diff --git a/reader/reader_test.go b/reader/reader_test.go index ba3172e..a7dd281 100644 --- a/reader/reader_test.go +++ b/reader/reader_test.go @@ -22,3 +22,18 @@ func TestReadDML(t *testing.T) { t.Errorf("dmlData[0].Sheet = %s; want Introduction", dmlData[0].Key) } } + +func TestNoFileReturnsError(t *testing.T) { + _, err := ReadDML("/home/bobbins.csv") + // if we get no error, something has gone wrong + if err == nil { + t.Errorf("Should have thrown error %s", err) + } +} + +func TestBadDMLLine(t *testing.T) { + _, err := ReadDML("/home/lemon/code/python/bcompiler-engine/tests/resources/datamap_empty_cols.csv") + if err != nil { + t.Errorf("This will trigger") + } +} |