-
Notifications
You must be signed in to change notification settings - Fork 84
/
messages_test.go
156 lines (139 loc) · 3.12 KB
/
messages_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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
package gofakes3
import (
"encoding/xml"
"fmt"
"io"
"testing"
"time"
)
func TestObjectListAddPrefix(t *testing.T) {
b := NewObjectList()
b.AddPrefix("prefix1")
if len(b.CommonPrefixes) != 1 {
t.Fatal("unexpected prefixes length")
}
// Duplicate prefix should not alter Bucket:
b.AddPrefix("prefix1")
if len(b.CommonPrefixes) != 1 {
t.Fatal("unexpected prefixes length")
}
b.AddPrefix("prefix2")
if len(b.CommonPrefixes) != 2 {
t.Fatal("unexpected prefixes length")
}
}
func TestContentTime(t *testing.T) {
type testMsg struct {
Foo string
Time ContentTime
}
const expected = "" +
"<testMsg>" +
"<Foo>bar</Foo>" +
"<Time>2019-01-01T12:00:00Z</Time>" +
"</testMsg>"
var v = testMsg{
Foo: "bar",
Time: NewContentTime(time.Date(2019, 1, 1, 7, 0, 0, 0, time.FixedZone("EST", -5*3600))), // 7am EST = 12pm UTC
}
out, err := xml.Marshal(&v)
if err != nil {
t.Fatal(err)
}
if string(out) != expected {
t.Fatalf("unexpected XML output: %s", string(out))
}
}
func TestContentTimeOmitEmpty(t *testing.T) {
type testMsg struct {
Foo string
Time ContentTime `xml:",omitempty"`
}
const expected = "" +
"<testMsg>" +
"<Foo>bar</Foo>" +
"</testMsg>"
var v = testMsg{Foo: "bar"}
out, err := xml.Marshal(&v)
if err != nil {
t.Fatal(err)
}
if string(out) != expected {
t.Fatalf("unexpected XML output: %s", string(out))
}
}
func TestErrorResultFromError(t *testing.T) {
t.Run("any-old-junk", func(t *testing.T) {
er := ErrorResultFromError(io.EOF)
if er.Code != ErrInternal {
t.Fatal()
}
})
t.Run("direct-code", func(t *testing.T) {
er := ErrorResultFromError(ErrBadDigest)
if er.Code != ErrBadDigest {
t.Fatal()
}
})
t.Run("wrapped-code", func(t *testing.T) {
er := ErrorResultFromError(&ErrorResponse{Code: ErrBadDigest})
if er.Code != ErrBadDigest {
t.Fatal()
}
})
t.Run("wrapped-code", func(t *testing.T) {
er := ErrorResultFromError(KeyNotFound("nup"))
if er.Code != ErrNoSuchKey {
t.Fatal()
}
})
}
func TestMFADeleteStatus(t *testing.T) {
type testMsg struct {
Foo string
Status MFADeleteStatus
}
const inputTpl = "" +
"<testMsg>" +
"<Foo>bar</Foo>" +
"<Status>%s</Status>" +
"</testMsg>"
for _, tc := range []struct {
in, out string
}{
{"Enabled", "Enabled"},
{"enabled", "Enabled"},
{"ENABLED", "Enabled"},
{"Disabled", "Disabled"},
} {
var msg testMsg
if err := xml.Unmarshal([]byte(fmt.Sprintf(inputTpl, tc.in)), &msg); err != nil {
t.Fatal(err)
}
if string(msg.Status) != tc.out {
t.Fatal()
}
}
var msg testMsg
if err := xml.Unmarshal([]byte(fmt.Sprintf(inputTpl, "QUACK QUACK")), &msg); err == nil {
t.Fatal()
}
}
func TestCopyObjectResult(t *testing.T) {
res := CopyObjectResult{
ETag: `"etag0"`,
LastModified: NewContentTime(time.Date(2019, 1, 1, 12, 0, 0, 0, time.UTC)),
}
const expected = "" +
"<CopyObjectResult>" +
"<ETag>"etag0"</ETag>" +
"<LastModified>2019-01-01T12:00:00Z</LastModified>" +
"</CopyObjectResult>"
out, err := xml.Marshal(&res)
if err != nil {
t.Fatal(err)
}
if string(out) != expected {
t.Fatalf("unexpected XML output: %s", string(out))
}
}