(t *testing.T)
| 29 | } |
| 30 | |
| 31 | func TestIfMatch(t *testing.T) { |
| 32 | p := Params{} |
| 33 | |
| 34 | // Read request |
| 35 | r, _ := http.NewRequest(http.MethodGet, "https://example.com/resource", nil) |
| 36 | w := httptest.NewRecorder() |
| 37 | ctx := humatest.NewContext(nil, r, w) |
| 38 | |
| 39 | p.IfMatch = []string{`"abc123"`, `W/"def456"`} |
| 40 | p.Resolve(ctx) |
| 41 | require.NoError(t, p.PreconditionFailed("abc123", time.Time{})) |
| 42 | require.NoError(t, p.PreconditionFailed("def456", time.Time{})) |
| 43 | |
| 44 | err := p.PreconditionFailed("bad", time.Time{}) |
| 45 | require.Error(t, err) |
| 46 | assert.Equal(t, http.StatusNotModified, err.GetStatus()) |
| 47 | |
| 48 | err = p.PreconditionFailed("", time.Time{}) |
| 49 | require.Error(t, err) |
| 50 | assert.Equal(t, http.StatusNotModified, err.GetStatus()) |
| 51 | |
| 52 | // Write request |
| 53 | r, _ = http.NewRequest(http.MethodPut, "https://example.com/resource", nil) |
| 54 | w = httptest.NewRecorder() |
| 55 | ctx = humatest.NewContext(nil, r, w) |
| 56 | |
| 57 | p.IfMatch = []string{`"abc123"`, `W/"def456"`} |
| 58 | p.Resolve(ctx) |
| 59 | require.NoError(t, p.PreconditionFailed("abc123", time.Time{})) |
| 60 | |
| 61 | err = p.PreconditionFailed("bad", time.Time{}) |
| 62 | require.Error(t, err) |
| 63 | assert.Equal(t, http.StatusPreconditionFailed, err.GetStatus()) |
| 64 | } |
| 65 | |
| 66 | func TestIfNoneMatch(t *testing.T) { |
| 67 | p := Params{} |
nothing calls this directly
no test coverage detected
searching dependent graphs…