Skip to content

Commit 07b6914

Browse files
committed
tests for empty query
1 parent a1dce04 commit 07b6914

2 files changed

Lines changed: 51 additions & 22 deletions

File tree

testing/go/framework.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ type ScriptTestAssertion struct {
129129
CopyFromStdInFile string
130130
}
131131

132+
// EmptyCommandTag is special command tag placeholder to check for the empty string
133+
const EmptyCommandTag = "EMPTY_COMMAND_TAG"
134+
132135
// Connection contains the default and current connections.
133136
type Connection struct {
134137
Default *pgx.Conn
@@ -249,10 +252,14 @@ func runScript(t *testing.T, ctx context.Context, script ScriptTest, conn *Conne
249252
require.NoError(t, err)
250253
}
251254
} else if assertion.ExpectedTag != "" {
252-
// check for command tag
253255
commandTag, err := conn.Exec(ctx, assertion.Query)
254256
require.NoError(t, err)
255-
assert.Equal(t, assertion.ExpectedTag, commandTag.String())
257+
tag := assertion.ExpectedTag
258+
if tag == EmptyCommandTag {
259+
tag = ""
260+
}
261+
262+
assert.Equal(t, tag, commandTag.String())
256263
} else {
257264
rows, err := conn.Query(ctx, assertion.Query, assertion.BindVars...)
258265
require.NoError(t, err)

testing/go/smoke_test.go

Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -743,26 +743,26 @@ func TestSmokeTests(t *testing.T) {
743743
SetUpScript: []string{
744744
"CREATE TABLE test (pk INT8 PRIMARY KEY);",
745745
"INSERT INTO test VALUES " +
746-
"(1), (2), (3), (4), (5), (6), (7), (8), (9), (10)," +
747-
"(11), (12), (13), (14), (15), (16), (17), (18), (19), (20)," +
748-
"(21), (22), (23), (24), (25), (26), (27), (28), (29), (30)," +
749-
"(31), (32), (33), (34), (35), (36), (37), (38), (39), (40)," +
750-
"(41), (42), (43), (44), (45), (46), (47), (48), (49), (50)," +
751-
"(51), (52), (53), (54), (55), (56), (57), (58), (59), (60)," +
752-
"(61), (62), (63), (64), (65), (66), (67), (68), (69), (70)," +
753-
"(71), (72), (73), (74), (75), (76), (77), (78), (79), (80)," +
754-
"(81), (82), (83), (84), (85), (86), (87), (88), (89), (90)," +
755-
"(91), (92), (93), (94), (95), (96), (97), (98), (99), (100)," +
756-
"(101), (102), (103), (104), (105), (106), (107), (108), (109), (110)," +
757-
"(111), (112), (113), (114), (115), (116), (117), (118), (119), (120)," +
758-
"(121), (122), (123), (124), (125), (126), (127), (128), (129), (130)," +
759-
"(131), (132), (133), (134), (135), (136), (137), (138), (139), (140)," +
760-
"(141), (142), (143), (144), (145), (146), (147), (148), (149), (150)," +
761-
"(151), (152), (153), (154), (155), (156), (157), (158), (159), (160)," +
762-
"(161), (162), (163), (164), (165), (166), (167), (168), (169), (170)," +
763-
"(171), (172), (173), (174), (175), (176), (177), (178), (179), (180)," +
764-
"(181), (182), (183), (184), (185), (186), (187), (188), (189), (190)," +
765-
"(191), (192), (193), (194), (195), (196), (197), (198), (199), (200);",
746+
"(1), (2), (3), (4), (5), (6), (7), (8), (9), (10)," +
747+
"(11), (12), (13), (14), (15), (16), (17), (18), (19), (20)," +
748+
"(21), (22), (23), (24), (25), (26), (27), (28), (29), (30)," +
749+
"(31), (32), (33), (34), (35), (36), (37), (38), (39), (40)," +
750+
"(41), (42), (43), (44), (45), (46), (47), (48), (49), (50)," +
751+
"(51), (52), (53), (54), (55), (56), (57), (58), (59), (60)," +
752+
"(61), (62), (63), (64), (65), (66), (67), (68), (69), (70)," +
753+
"(71), (72), (73), (74), (75), (76), (77), (78), (79), (80)," +
754+
"(81), (82), (83), (84), (85), (86), (87), (88), (89), (90)," +
755+
"(91), (92), (93), (94), (95), (96), (97), (98), (99), (100)," +
756+
"(101), (102), (103), (104), (105), (106), (107), (108), (109), (110)," +
757+
"(111), (112), (113), (114), (115), (116), (117), (118), (119), (120)," +
758+
"(121), (122), (123), (124), (125), (126), (127), (128), (129), (130)," +
759+
"(131), (132), (133), (134), (135), (136), (137), (138), (139), (140)," +
760+
"(141), (142), (143), (144), (145), (146), (147), (148), (149), (150)," +
761+
"(151), (152), (153), (154), (155), (156), (157), (158), (159), (160)," +
762+
"(161), (162), (163), (164), (165), (166), (167), (168), (169), (170)," +
763+
"(171), (172), (173), (174), (175), (176), (177), (178), (179), (180)," +
764+
"(181), (182), (183), (184), (185), (186), (187), (188), (189), (190)," +
765+
"(191), (192), (193), (194), (195), (196), (197), (198), (199), (200);",
766766
},
767767
Assertions: []ScriptTestAssertion{
768768
{
@@ -823,3 +823,25 @@ func TestSmokeTests(t *testing.T) {
823823
},
824824
})
825825
}
826+
827+
func TestEmptyQuery(t *testing.T) {
828+
RunScripts(t, []ScriptTest{
829+
{
830+
// TODO: we want to be able to assert that the empty query returns a specific postgres backend message,
831+
// EmptyQueryResponse. The pg library automatically converts this response to an empty-string CommandTag,
832+
// which we can't tell apart from other empty CommandTag responses. We do assert that the command tag is empty,
833+
// but it would nice to be able to assert a particular message type.
834+
Name: "Empty query test",
835+
Assertions: []ScriptTestAssertion{
836+
{
837+
Query: ";",
838+
ExpectedTag: EmptyCommandTag,
839+
},
840+
{
841+
Query: " ",
842+
ExpectedTag: EmptyCommandTag,
843+
},
844+
},
845+
},
846+
})
847+
}

0 commit comments

Comments
 (0)