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,17 +1,29 @@
package export
import "testing"
import (
"io/ioutil"
"os"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestCSVExporter_Export(t *testing.T) {
ch := make(chan interface{})
defer close(ch)
exporter := &CSV{
FileName: "out.csv",
Comma: ';',
}
go exporter.Export(ch)
_ = os.Remove(exporter.FileName)
exports := make(chan interface{})
go exporter.Export(exports)
ch <- []string{"1", "2"}
ch <- map[string]string{"key1": "value1", "key2": "value2"}
exports <- []string{"1", "2"}
exports <- map[string]string{"key1": "value1", "key2": "value2"}
close(exports)
time.Sleep(time.Millisecond)
contents, err := ioutil.ReadFile(exporter.FileName)
assert.NoError(t, err)
assert.Equal(t, "1;2\nvalue1;value2\n", string(contents))
}