-
Notifications
You must be signed in to change notification settings - Fork 8
/
main_test.go
49 lines (40 loc) · 1.15 KB
/
main_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main
import (
mock_main "LogViewer/mock"
"context"
"errors"
"io"
"os"
"strings"
"testing"
"time"
"github.com/golang/mock/gomock"
"github.com/rivo/tview"
"github.com/stretchr/testify/assert"
)
func Test_SaveToCSV(t *testing.T) {
c := gomock.NewController(t)
defer c.Finish()
table := mock_main.NewMockITable(c)
table.EXPECT().GetColumnCount().Return(3).AnyTimes()
table.EXPECT().GetRowCount().Return(3).AnyTimes()
table.EXPECT().GetCell(gomock.Any(), gomock.Any()).Return(&tview.TableCell{Text: "test"}).AnyTimes()
newView := new(tableView).Construct(context.Background())
newView.lang = "ru"
newView.table = table
t.Run("empty csvFileName", func(t *testing.T) {
newView.exportToCSV()
_, err := os.Stat(newView.csvFileName + ".csv")
assert.True(t, errors.Is(err, os.ErrNotExist))
})
t.Run("pass", func(t *testing.T) {
newView.csvFileName = "test"
newView.exportToCSV()
time.Sleep(time.Second)
f, err := os.Open(newView.csvFileName)
assert.False(t, errors.Is(err, os.ErrNotExist))
data, _ := io.ReadAll(f)
assert.Equal(t, strings.ReplaceAll(string(data), "\n", ""), `test,testtest,testtest,test`)
f.Close()
})
}