MCPcopy Create free account
hub / github.com/couchbase/sync_gateway / TestCacheablePass

Function TestCacheablePass

auth/oidc_test.go:710–754  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

708}
709
710func TestCacheablePass(t *testing.T) {
711 tests := []struct {
712 name string
713 headers http.Header
714 wantTTL time.Duration
715 wantOK bool
716 }{{
717 name: "valid Cache-Control",
718 headers: http.Header{
719 "Cache-Control": []string{"max-age=100"},
720 },
721 wantTTL: 100 * time.Second,
722 wantOK: true,
723 }, {
724 name: "valid Date and Expires",
725 headers: http.Header{
726 "Date": []string{"Thu, 01 Dec 1983 22:00:00 GMT"},
727 "Expires": []string{"Fri, 02 Dec 1983 01:00:00 GMT"},
728 },
729 wantTTL: 10800 * time.Second,
730 wantOK: true,
731 }, {
732 name: "Cache-Control supersedes Date and Expires",
733 headers: http.Header{
734 "Cache-Control": []string{"max-age=100"},
735 "Date": []string{"Thu, 01 Dec 1983 22:00:00 GMT"},
736 "Expires": []string{"Fri, 02 Dec 1983 01:00:00 GMT"},
737 },
738 wantTTL: 100 * time.Second,
739 wantOK: true,
740 }, {
741 name: "no caching headers",
742 headers: http.Header{},
743 wantOK: false,
744 }}
745
746 for _, tc := range tests {
747 t.Run(tc.name, func(t *testing.T) {
748 ttl, ok, err := cacheable(tc.headers)
749 require.NoError(t, err, "Error getting expiry")
750 assert.Equal(t, tc.wantTTL, ttl, "TTL mismatch")
751 assert.Equal(t, tc.wantOK, ok, " incorrect ok value")
752 })
753 }
754}
755
756func TestCacheableFail(t *testing.T) {
757 tests := []struct {

Callers

nothing calls this directly

Calls 3

cacheableFunction · 0.85
RunMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected