-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwrite_test.go
More file actions
98 lines (87 loc) · 2.37 KB
/
Copy pathwrite_test.go
File metadata and controls
98 lines (87 loc) · 2.37 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
package cabrillo
import (
"os"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestTestdataRoundtrip(t *testing.T) {
entries, err := os.ReadDir("testdata")
require.NoError(t, err)
for _, entry := range entries {
t.Run(entry.Name(), func(t *testing.T) {
originalFile, err := os.Open("testdata/" + entry.Name())
require.NoError(t, err)
defer originalFile.Close()
originalLog, err := Read(originalFile)
require.NoError(t, err)
for tag, value := range originalLog.Custom {
if value == "" {
delete(originalLog.Custom, tag)
}
}
outputFile, err := os.CreateTemp("", "cabrillo-roundtrip-"+entry.Name()+"-*")
assert.NoError(t, err)
processedFilename := outputFile.Name()
err = Write(outputFile, originalLog, true)
assert.NoError(t, err)
outputFile.Close()
processedFile, err := os.Open(processedFilename)
require.NoError(t, err)
defer processedFile.Close()
processedLog, err := Read(processedFile)
assert.NoError(t, err)
assert.Equal(t, originalLog, processedLog)
})
}
}
func TestWrapRows(t *testing.T) {
tests := []struct {
name string
tag Tag
value string
expected []string
}{
{
name: "empty",
tag: SoapboxTag,
value: "",
expected: []string{"SOAPBOX:"},
},
{
name: "short",
tag: SoapboxTag,
value: "1234567890",
expected: []string{"SOAPBOX: 1234567890"},
},
{
name: "long without whitespace",
tag: SoapboxTag,
value: "12345678901234567890123456789012345678901234567890123456789012345678901234567890",
expected: []string{
"SOAPBOX: 123456789012345678901234567890123456789012345678901234567890123456",
"SOAPBOX: 78901234567890",
},
},
{
name: "long with whitespace",
tag: SoapboxTag,
value: "123456789 123456789 123456789 123456789 123456789 123456789 123456789 1234567890",
expected: []string{
"SOAPBOX: 123456789 123456789 123456789 123456789 123456789 123456789",
"SOAPBOX: 123456789 1234567890",
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
actual := wrapRows(tt.tag, tt.value, true)
require.Equal(t, len(tt.expected), len(actual))
for i, row := range actual {
line := row.String()
assert.True(t, len(line) <= 75, "len %d: %s = %d", i, line, len(line))
assert.Equal(t, tt.expected[i], line)
}
})
}
}