Skip to content

Commit

Permalink
Add test on writing csv to dir
Browse files Browse the repository at this point in the history
  • Loading branch information
rnixik committed Jul 29, 2018
1 parent cec1f2b commit 27218d7
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions csv_writer_test.go
Expand Up @@ -37,6 +37,36 @@ func TestCsvWriterWriteRows(t *testing.T) {
}
}

func TestCsvWriterWriteRowsToDir(t *testing.T) {
fw := NewTestFileWriter()
writer := NewCsvWriter(fw, "", "/tmp/some_dir", ";")
rows1 := make([]*map[string]interface{}, 0)
rows1 = append(rows1, &map[string]interface{}{
"id": 1,
"name": "Name 1",
})
rows2 := make([]*map[string]interface{}, 0)
rows2 = append(rows2, &map[string]interface{}{
"id": 1,
"value": 5,
})

writer.WriteRows("some_table1", []string{"id", "name"}, rows1)
writer.WriteRows("some_table2", []string{"id", "value"}, rows2)
result1 := fw.getContents("/tmp/some_dir/some_table1.csv")
result2 := fw.getContents("/tmp/some_dir/some_table2.csv")
expected1 := "\"id\";\"name\"\r\n"
expected1 += "1;\"Name 1\"\r\n"
if expected1 != result1 {
t.Errorf("Expected:\n%sGot:\n%s", expected1, result1)
}
expected2 := "\"id\";\"value\"\r\n"
expected2 += "1;5\r\n"
if expected2 != result2 {
t.Errorf("Expected:\n%sGot:\n%s", expected2, result2)
}
}

func TestCsvWriterWriteDDL(t *testing.T) {
fw := NewTestFileWriter()
writer := NewCsvWriter(fw, "result.csv", "", ",")
Expand Down

0 comments on commit 27218d7

Please sign in to comment.