-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathslice_test.go
More file actions
108 lines (84 loc) · 2.58 KB
/
Copy pathslice_test.go
File metadata and controls
108 lines (84 loc) · 2.58 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package htmldump_test
import (
"bytes"
"strings"
"testing"
"time"
"github.com/oslyak/htmldump"
"github.com/brianvoe/gofakeit/v7"
"github.com/stretchr/testify/require"
)
type order struct {
Column string
}
type filter struct {
IncludeRemoved bool
Limit uint64
Offset uint64
orderPtr *order
order
}
type filterAccounts struct {
Name string
OwnerID int64
ExchangeID int64
today time.Time
yesterdayPtr *time.Time
EmptyDatePtr *time.Time
EmptyPointer *filter
EmptyFilter filter
filter
}
func newFilterAccounts() filterAccounts {
now := time.Now()
yesterday := now.AddDate(0, 0, -1)
return filterAccounts{
Name: gofakeit.Word(),
OwnerID: int64(gofakeit.Uint8()),
ExchangeID: int64(gofakeit.Uint8()),
today: now,
yesterdayPtr: &yesterday,
filter: filter{
IncludeRemoved: gofakeit.Bool(),
Limit: uint64(gofakeit.Uint16()),
Offset: uint64(gofakeit.Uint16()),
order: order{
Column: gofakeit.Word(),
},
orderPtr: &order{Column: `pointer`},
},
}
}
func TestDumpSlice(t *testing.T) {
t.Parallel()
slice := []string{`a`, `b`, `c`}
buffer := bytes.NewBuffer([]byte{})
err := htmldump.ToHTML(buffer, slice)
require.NoError(t, err)
table := extractHTMLTable(t, buffer.String())
table = removeStyle(t, table)
expect := `<caption>[]string (length: 3)</caption>`
require.Contains(t, table, expect)
expect = `<tr><th>index</th><th>value</th></tr><tr><th>int</th><th>string</th></tr>`
require.Contains(t, table, expect)
expect = `<tr><td>0</td><td>a</td></tr><tr><td>1</td><td>b</td></tr><tr><td>2</td><td>c</td></tr>`
require.Contains(t, table, expect)
filter := newFilterAccounts()
slice1 := []*filterAccounts{nil, &filter, &filter, &filter}
// dump.ToHTMLAndOpen(`/tmp/dump_slice_test.html`, slice1)
buffer = bytes.NewBuffer([]byte{})
err = htmldump.ToHTML(buffer, slice1)
require.NoError(t, err)
table = extractHTMLTable(t, buffer.String())
table = removeStyle(t, table)
expect = `<caption>[]*dump_test.filterAccounts`
require.Contains(t, table, expect)
expect = `<caption>[]*dump_test.filterAccounts`
require.Contains(t, table, expect)
strBuilder := strings.Builder{}
strBuilder.WriteString(`<tr><th>index</th><th>Name</th><th>OwnerID</th><th>ExchangeID</th>`)
strBuilder.WriteString(`<th>today</th><th>yesterdayPtr</th>`)
strBuilder.WriteString(`<th>EmptyDatePtr</th><th colspan="5">EmptyPointer(*filter)</th>`)
strBuilder.WriteString(`<th colspan="5">EmptyFilter(filter)</th><th colspan="5">filter</th></tr>`)
require.Contains(t, table, strBuilder.String())
}