Added more tests and refactored exporter tests. Added code coverage badge.

This commit is contained in:
Musab Gültekin
2019-07-02 14:53:06 +03:00
parent 4ab7cfd904
commit b355a566cf
9 changed files with 144 additions and 17 deletions

View File

@ -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))
}