MCPcopy Create free account
hub / github.com/datastax/cql-proxy / TestIsIdempotentInsertStmt

Function TestIsIdempotentInsertStmt

parser/parse_insert_test.go:23–61  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

21)
22
23func TestIsIdempotentInsertStmt(t *testing.T) {
24 var tests = []struct {
25 query string
26 idempotent bool
27 hasError bool
28 msg string
29 }{
30 {"INSERT INTO table (a, b, c) VALUES (1, 'a', 0.1)", true, false, "simple"},
31 {"INSERT INTO table (a, b, c) VALUES (1, 'a', 0.1);", true, false, "semicolon"},
32 {"INSERT INTO ks.table (a, b, c) VALUES (1, 'a', 0.1)", true, false, "simple qualified table name"},
33 {"INSERT INTO table () VALUES ()", true, false, "no identifier of values"},
34 {"INSERT INTO table JSON '{}'", true, false, "JSON"},
35
36 // Invalid
37 {"INSERT table (a, b, c) VALUES (1, 'a', 0.1)", false, true, "missing 'INTO'"},
38 {"INSERT INTO (a, b, c) VALUES (1, 'a', 0.1)", false, true, "missing table name"},
39 {"INSERT INTO table a, b, c) VALUES (1, 'a', 0.1)", false, true, "missing opening paren. on identifiers"},
40 {"INSERT INTO table (a, b, c VALUES (1, 'a', 0.1)", false, true, "missing closing paren on identifiers"},
41 {"INSERT INTO table (a, b, c) (1, 'a', 0.1)", false, true, "missing 'VALUES'"},
42 {"INSERT INTO table (0, b, c) VALUES (1, 'a', 0.1)", false, true, "unexpected term in identifiers"},
43 {"INSERT INTO table (a, b, c) VALUES (invalid, 'a', 0.1)", false, true, "invalid value"},
44 {"INSERT INTO table (a, b, c) VALUES 1, 'a', 0.1)", false, true, "missing opening paren. on values"},
45 {"INSERT INTO table (a, b, c) VALUES (1, 'a', 0.1", false, true, "missing closing paren. on values"},
46
47 // Not idempotent
48 {"INSERT INTO table (a, b, c) VALUES (now(), 'a', 0.1)", false, false, "simple w/ 'now()'"},
49 {"INSERT INTO table (a, b, c) VALUES (0, uuid(), 0.1)", false, false, "simple w/ 'uuid()'"},
50 {"INSERT INTO table (a, b, c) VALUES (1, 'a', 0.1) IF NOT EXISTS", false, false, "simple w/ LWT"},
51 {"INSERT INTO table () VALUES () IF NOT EXIST", false, false, "no identifier of values w/ LWT"},
52 {"INSERT INTO table JSON '{}' IF NOT EXIST", false, false, "'JSON' w/ LWT"},
53 {"INSERT INTO table JSON '{}' IF NOT EXIST;", false, false, "'JSON' w/ LWT and semicolon"},
54 }
55
56 for _, tt := range tests {
57 idempotent, err := IsQueryIdempotent(tt.query)
58 assert.True(t, (err != nil) == tt.hasError, tt.msg)
59 assert.Equal(t, tt.idempotent, idempotent, "invalid idempotency", tt.msg)
60 }
61}

Callers

nothing calls this directly

Calls 1

IsQueryIdempotentFunction · 0.85

Tested by

no test coverage detected