Skip to content

Commit 6834e48

Browse files
committed
test: make "expect an empty body" expressible (it silently wasn't)
Execute() gated the body comparison on `test.Expected != ""`, so an empty Expected meant "don't check the body" — which is also exactly how a ported test has to spell PostgREST's `shouldRespondWith ""`. The two are indistinguishable, so every ported test expecting an empty body silently degraded to a status-only check: 116 of ~800 across insert (17), update (16), range (24), rpc (14), query (13), embed_inner_join (15), delete (7) and others. That is a hole in a suite whose entire purpose is catching PostgREST deviations: it cannot see the one class of response PostgREST defines by absence — and writes default to `Prefer: return=minimal`, so that class is every write. Adds an explicit ExpectedEmpty bool. Additive: Go's zero value keeps every existing test's behaviour unchanged. Marks the three insert cases whose PostgREST comment reads `shouldRespondWith ""` with matchStatus 201. They fail against the current POST handler — see the next commit. The remaining 113 are left for triage: "Expected is empty" does not by itself mean "PostgREST expects empty" (many are GETs where the porter simply didn't fill in the body), so they need reading against their Haskell comment rather than a bulk flip.
1 parent ec7d0a9 commit 6834e48

2 files changed

Lines changed: 30 additions & 15 deletions

File tree

test/common.go

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,21 @@ type Command struct {
2929

3030
// We don't embed Command to simplify tests writing
3131
type Test struct {
32-
Description string
33-
Method string
34-
Query string
35-
Body string
36-
Headers Headers
37-
Expected string
32+
Description string
33+
Method string
34+
Query string
35+
Body string
36+
Headers Headers
37+
// Expected is the response body to compare against, JSON-normalized.
38+
// An empty Expected means "no expectation" and the body is NOT checked —
39+
// so it cannot express PostgREST's `shouldRespondWith ""`. Use
40+
// ExpectedEmpty for that.
41+
Expected string
42+
// ExpectedEmpty asserts the response body is empty. Needed because many
43+
// ported PostgREST tests expect exactly that (writes default to
44+
// `Prefer: return=minimal`), and encoding it as `Expected: ""` silently
45+
// degraded those tests to status-only checks.
46+
ExpectedEmpty bool
3847
ExpectedHeaders map[string]string
3948
Status int
4049
}
@@ -134,6 +143,12 @@ func Execute(t *testing.T, config Config, tests []Test) {
134143
body, headers, status, err := Exec(client, config, command)
135144
if err != nil {
136145
t.Errorf("Error: %v", err)
146+
} else if test.ExpectedEmpty {
147+
if len(bytes.TrimSpace(body)) != 0 {
148+
t.Errorf("\n\n%d. %v\nExpected an empty body, \ngot \n\t\"%v\" \n\n(query string -> \"%v\")", i,
149+
test.Description, string(body), test.Query)
150+
break
151+
}
137152
} else if test.Expected != "" {
138153
if v, ok := test.Headers["Accept"]; ok && strings.Contains(v[0], "text/csv") {
139154
s1 = test.Expected

test/postgrest/insert_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ func TestPostgREST_Insert(t *testing.T) {
3131
, "boolean": false, "date": "1900-01-01", "money": "$3.99"
3232
, "enum": "foo"
3333
}`,
34-
Headers: nil,
35-
Expected: ``,
36-
Status: 201,
34+
Headers: nil,
35+
ExpectedEmpty: true,
36+
Status: 201,
3737
},
3838
// it "filters columns in result using &select" $
3939
// request methodPost "/menagerie?select=integer,varchar" [("Prefer", "return=representation")]
@@ -80,9 +80,9 @@ func TestPostgREST_Insert(t *testing.T) {
8080
, "boolean": false, "date": "1900-01-01", "money": "$3.99"
8181
, "enum": "foo"
8282
}]`,
83-
Headers: nil,
84-
Expected: ``,
85-
Status: 201,
83+
Headers: nil,
84+
ExpectedEmpty: true,
85+
Status: 201,
8686
},
8787
// request methodPost "/menagerie?select=integer,varchar"
8888
// [("Prefer", "return=minimal")]
@@ -105,9 +105,9 @@ func TestPostgREST_Insert(t *testing.T) {
105105
, "boolean": false, "date": "1900-01-01", "money": "$3.99"
106106
, "enum": "foo"
107107
}]`,
108-
Headers: test.Headers{"Prefer": {"return=minimal"}},
109-
Expected: ``,
110-
Status: 201,
108+
Headers: test.Headers{"Prefer": {"return=minimal"}},
109+
ExpectedEmpty: true,
110+
Status: 201,
111111
},
112112
// context "non uniform json array" $ do
113113
// it "rejects json array that isn't exclusivily composed of objects" $

0 commit comments

Comments
 (0)