MCPcopy Create free account
hub / github.com/AbelChe/evil_minio / TestGetCacheControlOpts

Function TestGetCacheControlOpts

cmd/disk-cache-utils_test.go:27–61  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

25)
26
27func TestGetCacheControlOpts(t *testing.T) {
28 expiry, _ := time.Parse(http.TimeFormat, "Wed, 21 Oct 2015 07:28:00 GMT")
29
30 testCases := []struct {
31 cacheControlHeaderVal string
32 expiryHeaderVal time.Time
33 expectedCacheControl *cacheControl
34 expectedErr bool
35 }{
36 {"", timeSentinel, nil, false},
37 {"max-age=2592000, public", timeSentinel, &cacheControl{maxAge: 2592000, sMaxAge: 0, minFresh: 0, expiry: time.Time{}}, false},
38 {"max-age=2592000, no-store", timeSentinel, &cacheControl{maxAge: 2592000, sMaxAge: 0, noStore: true, minFresh: 0, expiry: time.Time{}}, false},
39 {"must-revalidate, max-age=600", timeSentinel, &cacheControl{maxAge: 600, sMaxAge: 0, minFresh: 0, expiry: time.Time{}}, false},
40 {"s-maxAge=2500, max-age=600", timeSentinel, &cacheControl{maxAge: 600, sMaxAge: 2500, minFresh: 0, expiry: time.Time{}}, false},
41 {"s-maxAge=2500, max-age=600", expiry, &cacheControl{maxAge: 600, sMaxAge: 2500, minFresh: 0, expiry: time.Date(2015, time.October, 21, 0o7, 28, 0o0, 0o0, time.UTC)}, false},
42 {"s-maxAge=2500, max-age=600s", timeSentinel, &cacheControl{maxAge: 600, sMaxAge: 2500, minFresh: 0, expiry: time.Time{}}, true},
43 }
44
45 for _, testCase := range testCases {
46 t.Run("", func(t *testing.T) {
47 m := make(map[string]string)
48 m["cache-control"] = testCase.cacheControlHeaderVal
49 if !testCase.expiryHeaderVal.Equal(timeSentinel) {
50 m["expires"] = testCase.expiryHeaderVal.String()
51 }
52 c := cacheControlOpts(ObjectInfo{UserDefined: m, Expires: testCase.expiryHeaderVal})
53 if testCase.expectedErr && (c != nil) {
54 t.Errorf("expected err, got <nil>")
55 }
56 if !testCase.expectedErr && !reflect.DeepEqual(c, testCase.expectedCacheControl) {
57 t.Errorf("expected %v, got %v", testCase.expectedCacheControl, c)
58 }
59 })
60 }
61}
62
63func TestIsMetadataSame(t *testing.T) {
64 testCases := []struct {

Callers

nothing calls this directly

Calls 3

cacheControlOptsFunction · 0.85
StringMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected