(t *testing.T)
| 25 | ) |
| 26 | |
| 27 | func 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 | |
| 63 | func TestIsMetadataSame(t *testing.T) { |
| 64 | testCases := []struct { |
nothing calls this directly
no test coverage detected