-
Notifications
You must be signed in to change notification settings - Fork 0
/
export_test.go
84 lines (70 loc) · 2.5 KB
/
export_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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package export
import (
"fmt"
"os"
"service/user"
"testing"
)
type MockWriteErr struct {
}
func (m MockWriteErr) WriteRecord(records []Records) error {
return fmt.Errorf("cannot create record")
}
func (m MockWriteErr) WriteFile(name string, data []byte, perm os.FileMode) error {
return fmt.Errorf("cannot write in file")
}
var user1 = user.User{FirstName: "Test Item 1", LastName: "Test", Email: "test", Address: "test", Created: "test", Balance: "test"}
var user2 = user.User{FirstName: "Test Item 1", LastName: "Test", Email: "test", Address: "test", Created: "test", Balance: "test"}
var user3 = user.User{FirstName: "Test Item 1", LastName: "Test", Email: "test", Address: "test", Created: "test", Balance: "test"}
var user4 = user.User{FirstName: "Keith", LastName: "Hilpert", Email: "Keith.Hilpert@sammy.name", Address: "230 Kenna Harbor", Created: "March 11, 2019", Balance: "$8,419.47"}
var user5 = user.User{FirstName: "Brendan", LastName: "Mosciski", Email: "Keith.Hilpert@sammy.name", Address: "230 Kenna Harbor", Created: "March 11, 2019", Balance: "$8,419.47"}
func TestExportRecordsError(t *testing.T) {
var w = &MockWriteErr{}
collections := make(map[string][]user.User)
collections["T"] = append(collections["T"], user1, user2, user3, user4, user5)
err := Execute(collections, w)
if err == nil {
t.Errorf("Read dates error")
}
}
func TestWriteRecordError(t *testing.T) {
var w = &MockWriteErr{}
var users []user.User
var records []Records
users = append(users, user1, user2)
tempRecord := Records{Index: "T", Records: users, Total: len(users)}
records = append(records, tempRecord)
err := w.WriteRecord(records)
if err == nil {
t.Errorf("write record error")
}
}
type MockWriteSuccess struct {
}
func (m MockWriteSuccess) WriteRecord(records []Records) error {
return nil
}
func (m MockWriteSuccess) WriteFile(name string, data []byte, perm os.FileMode) error {
return nil
}
func TestExportRecordsSuccess(t *testing.T) {
var w = &MockWriteSuccess{}
collections := make(map[string][]user.User)
collections["T"] = append(collections["T"], user1, user2, user3)
err := Execute(collections, w)
if err != nil {
t.Errorf("Read dates error")
}
}
func TestWriteRecordSuccess(t *testing.T) {
var w = &MockWriteSuccess{}
var users []user.User
var records []Records
users = append(users, user1, user2)
tempRecord := Records{Index: "T", Records: users, Total: len(users)}
records = append(records, tempRecord)
err := w.WriteRecord(records)
if err != nil {
t.Errorf("write record error")
}
}