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

Function TestCacheControlMaxAgePass

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

Source from the content-addressed store, hash-verified

789}
790
791func TestCacheControlMaxAgePass(t *testing.T) {
792 tests := []struct {
793 name string
794 header http.Header
795 wantMaxAge time.Duration
796 wantOK bool
797 }{{
798 name: "Cache-Control header with valid max-age directive",
799 header: http.Header{
800 "Cache-Control": []string{"max-age=12"},
801 },
802 wantMaxAge: 12 * time.Second,
803 wantOK: true,
804 }, {
805 name: "Cache-Control header with invalid max-age directive",
806 header: http.Header{
807 "Cache-Control": []string{"max-age=-12"},
808 },
809 wantMaxAge: 0,
810 wantOK: false,
811 }, {
812 name: "Cache-Control header with zero max-age directive",
813 header: http.Header{
814 "Cache-Control": []string{"max-age=0"},
815 },
816 wantMaxAge: 0,
817 wantOK: false,
818 }, {
819 name: "Cache-Control header with valid max-age set as public",
820 header: http.Header{
821 "Cache-Control": []string{"public, max-age=12"},
822 },
823 wantMaxAge: 12 * time.Second,
824 wantOK: true,
825 }, {
826 name: "Cache-Control header with valid max-age set as public and must-revalidate",
827 header: http.Header{
828 "Cache-Control": []string{"public, max-age=40192, must-revalidate"},
829 },
830 wantMaxAge: 40192 * time.Second,
831 wantOK: true,
832 }, {
833 name: "Cache-Control header with invalid max-age set as public and must-revalidate",
834 header: http.Header{
835 "Cache-Control": []string{"public, not-max-age=12, must-revalidate"},
836 },
837 wantMaxAge: time.Duration(0),
838 wantOK: false,
839 }}
840
841 for _, tc := range tests {
842 t.Run(tc.name, func(t *testing.T) {
843 maxAge, ok, err := cacheControlMaxAge(tc.header)
844 require.NoError(t, err, "error checking max age and expiry")
845 assert.Equal(t, tc.wantMaxAge, maxAge, "max age mismatch")
846 assert.Equal(t, tc.wantOK, ok, " incorrect ok value")
847 })
848 }

Callers

nothing calls this directly

Calls 3

cacheControlMaxAgeFunction · 0.85
RunMethod · 0.65
EqualMethod · 0.45

Tested by

no test coverage detected