Added more tests and refactored exporter tests. Added code coverage badge.
This commit is contained in:
@ -1,16 +1,27 @@
|
||||
package export
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestJSONExporter_Export(t *testing.T) {
|
||||
ch := make(chan interface{})
|
||||
defer close(ch)
|
||||
|
||||
exporter := &JSON{
|
||||
FileName: "out.json",
|
||||
Indent: " ",
|
||||
}
|
||||
go exporter.Export(ch)
|
||||
_ = os.Remove(exporter.FileName)
|
||||
exports := make(chan interface{})
|
||||
go exporter.Export(exports)
|
||||
|
||||
ch <- map[string]string{"key": "value"}
|
||||
exports <- map[string]string{"key": "value"}
|
||||
close(exports)
|
||||
time.Sleep(time.Millisecond)
|
||||
|
||||
contents, err := ioutil.ReadFile(exporter.FileName)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, "{\n \"key\": \"value\"\n}\n", string(contents))
|
||||
}
|
||||
|
Reference in New Issue
Block a user