-
Notifications
You must be signed in to change notification settings - Fork 0
/
object_test.go
113 lines (90 loc) · 2.81 KB
/
object_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
package ls3
import (
"github.com/stretchr/testify/assert"
"net/http"
"testing"
"time"
)
func Test_checkConditionalRequest(t *testing.T) {
obj := &Object{
ETag: "",
LastModified: time.Date(2022, 01, 01, 0, 0, 0, 0, time.UTC),
}
t.Run("unconditional", func(t *testing.T) {
code, err := checkConditionalRequest(http.Header{}, obj)
assert.NoError(t, err)
assert.Equal(t, 0, code)
})
t.Run("If-Match true", func(t *testing.T) {
code, err := checkConditionalRequest(http.Header{
"If-Match": []string{""},
}, obj)
assert.NoError(t, err)
assert.Equal(t, 0, code)
})
t.Run("If-Match false", func(t *testing.T) {
code, err := checkConditionalRequest(http.Header{
"If-Match": []string{"some other etag"},
}, obj)
assert.NoError(t, err)
assert.Equal(t, http.StatusPreconditionFailed, code)
})
t.Run("If-None-Match true", func(t *testing.T) {
code, err := checkConditionalRequest(http.Header{
"If-None-Match": []string{"some other etag"},
}, obj)
assert.NoError(t, err)
assert.Equal(t, 0, code)
})
t.Run("If-None-Match false", func(t *testing.T) {
code, err := checkConditionalRequest(http.Header{
"If-None-Match": []string{""},
}, obj)
assert.NoError(t, err)
assert.Equal(t, http.StatusNotModified, code)
})
t.Run("If-Modified-Since true", func(t *testing.T) {
code, err := checkConditionalRequest(http.Header{
"If-Modified-Since": []string{"Sat, 02 Jan 2022 00:00:00 GMT"},
}, obj)
assert.NoError(t, err)
assert.Equal(t, 0, code)
})
t.Run("If-Modified-Since false", func(t *testing.T) {
code, err := checkConditionalRequest(http.Header{
"If-Modified-Since": []string{"Thu, 31 Dec 2021 00:00:00 GMT"},
}, obj)
assert.NoError(t, err)
assert.Equal(t, http.StatusNotModified, code)
})
t.Run("If-Unmodified-Since true", func(t *testing.T) {
code, err := checkConditionalRequest(http.Header{
"If-Unmodified-Since": []string{"Sat, 02 Jan 2022 00:00:00 GMT"},
}, obj)
assert.NoError(t, err)
assert.Equal(t, 0, code)
})
t.Run("If-Unmodified-Since false", func(t *testing.T) {
code, err := checkConditionalRequest(http.Header{
"If-Unmodified-Since": []string{"Thu, 31 Dec 2021 00:00:00 GMT"},
}, obj)
assert.NoError(t, err)
assert.Equal(t, http.StatusPreconditionFailed, code)
})
t.Run("Consideration-1", func(t *testing.T) {
code, err := checkConditionalRequest(http.Header{
"If-Match": []string{""},
"If-Modified-Since": []string{"Sat, 02 Jan 2022 00:00:00 GMT"},
}, obj)
assert.NoError(t, err)
assert.Equal(t, 0, code)
})
t.Run("Consideration-2", func(t *testing.T) {
code, err := checkConditionalRequest(http.Header{
"If-None-Match": []string{""},
"If-Modified-Since": []string{"Sat, 02 Jan 2022 00:00:00 GMT"},
}, obj)
assert.NoError(t, err)
assert.Equal(t, http.StatusNotModified, code)
})
}