| 754 | } |
| 755 | |
| 756 | func TestCacheableFail(t *testing.T) { |
| 757 | tests := []struct { |
| 758 | name string |
| 759 | header http.Header |
| 760 | wantTTL time.Duration |
| 761 | wantOK bool |
| 762 | }{{ |
| 763 | name: "invalid Cache-Control short-circuits", |
| 764 | header: http.Header{ |
| 765 | "Cache-Control": []string{"max-age"}, |
| 766 | "Date": []string{"Thu, 01 Dec 1983 22:00:00 GMT"}, |
| 767 | "Expires": []string{"Fri, 02 Dec 1983 01:00:00 GMT"}, |
| 768 | }, |
| 769 | wantTTL: 0, |
| 770 | wantOK: false, |
| 771 | }, { |
| 772 | name: "no Cache-Control invalid Expires", |
| 773 | header: http.Header{ |
| 774 | "Date": []string{"Thu, 01 Dec 1983 22:00:00 GMT"}, |
| 775 | "Expires": []string{"boo"}, |
| 776 | }, |
| 777 | wantTTL: 0, |
| 778 | wantOK: false, |
| 779 | }} |
| 780 | |
| 781 | for _, tc := range tests { |
| 782 | t.Run(tc.name, func(t *testing.T) { |
| 783 | ttl, ok, err := cacheable(tc.header) |
| 784 | require.Error(t, err, "No error checking max age and expiry") |
| 785 | assert.Equal(t, tc.wantTTL, ttl, "TTL mismatch") |
| 786 | assert.Equal(t, tc.wantOK, ok, " incorrect ok value") |
| 787 | }) |
| 788 | } |
| 789 | } |
| 790 | |
| 791 | func TestCacheControlMaxAgePass(t *testing.T) { |
| 792 | tests := []struct { |