JSON renamed to JSONLine. JSON List support added.

This commit is contained in:
Musab Gültekin
2019-07-14 03:30:59 +03:00
parent d19465c44a
commit dfabcb84fd
3 changed files with 81 additions and 18 deletions

View File

@ -8,8 +8,8 @@ import (
"time"
)
func TestJSONExporter_Export(t *testing.T) {
exporter := &JSON{
func TestJSONLineExporter_Export(t *testing.T) {
exporter := &JSONLine{
FileName: "out.json",
Indent: " ",
}
@ -19,9 +19,26 @@ func TestJSONExporter_Export(t *testing.T) {
exports <- map[string]string{"key": "value"}
close(exports)
time.Sleep(time.Millisecond)
time.Sleep(time.Millisecond) // Wait for writing to disk
contents, err := ioutil.ReadFile(exporter.FileName)
assert.NoError(t, err)
assert.Equal(t, "{\n \"key\": \"value\"\n}\n", string(contents))
}
func TestJSONExporter_Export(t *testing.T) {
exporter := &JSON{
FileName: "out.json",
}
_ = os.Remove(exporter.FileName)
exports := make(chan interface{})
go exporter.Export(exports)
exports <- map[string]string{"key": "value"}
close(exports)
time.Sleep(time.Millisecond) // Wait for writing to disk
contents, err := ioutil.ReadFile(exporter.FileName)
assert.NoError(t, err)
assert.Equal(t, "[\n\t{\"key\":\"value\"}\n]\n", string(contents))
}