MCPcopy
hub / github.com/danielgtaylor/huma / TestIfMatch

Function TestIfMatch

conditional/params_test.go:31–64  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

29}
30
31func 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
66func TestIfNoneMatch(t *testing.T) {
67 p := Params{}

Callers

nothing calls this directly

Calls 5

ResolveMethod · 0.95
PreconditionFailedMethod · 0.95
NewContextFunction · 0.92
ErrorMethod · 0.65
GetStatusMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…