(t *testing.T)
| 104 | } |
| 105 | |
| 106 | func TestIfModifiedSince(t *testing.T) { |
| 107 | p := Params{} |
| 108 | |
| 109 | now, err := time.Parse(time.RFC3339, "2021-01-01T12:00:00Z") |
| 110 | require.NoError(t, err) |
| 111 | |
| 112 | before, err := time.Parse(time.RFC3339, "2020-01-01T12:00:00Z") |
| 113 | require.NoError(t, err) |
| 114 | |
| 115 | after, err := time.Parse(time.RFC3339, "2022-01-01T12:00:00Z") |
| 116 | require.NoError(t, err) |
| 117 | |
| 118 | // Read request |
| 119 | r, _ := http.NewRequest(http.MethodGet, "https://example.com/resource", nil) |
| 120 | w := httptest.NewRecorder() |
| 121 | ctx := humatest.NewContext(nil, r, w) |
| 122 | |
| 123 | p.IfModifiedSince = now |
| 124 | |
| 125 | p.Resolve(ctx) |
| 126 | require.Error(t, p.PreconditionFailed("", before)) |
| 127 | require.Error(t, p.PreconditionFailed("", now)) |
| 128 | require.NoError(t, p.PreconditionFailed("", after)) |
| 129 | |
| 130 | // Write request |
| 131 | r, _ = http.NewRequest(http.MethodPut, "https://example.com/resource", nil) |
| 132 | w = httptest.NewRecorder() |
| 133 | ctx = humatest.NewContext(nil, r, w) |
| 134 | |
| 135 | p.IfModifiedSince = now |
| 136 | |
| 137 | p.Resolve(ctx) |
| 138 | perr := p.PreconditionFailed("", before) |
| 139 | require.Error(t, perr) |
| 140 | assert.Equal(t, http.StatusPreconditionFailed, perr.GetStatus()) |
| 141 | } |
| 142 | |
| 143 | func TestIfUnmodifiedSince(t *testing.T) { |
| 144 | p := Params{} |
nothing calls this directly
no test coverage detected
searching dependent graphs…