System-level single-node named param testing
@@ -245,7 +245,7 @@ func Test_SingleNodeConcurrentRequestsCompressed(t *testing.T) {
}
}
-func Test_SingleParameterizedNode(t *testing.T) {
+func Test_SingleNodeParameterized(t *testing.T) {
node := mustNewLeaderNode()
defer node.Deprovision()
@@ -288,6 +288,49 @@ func Test_SingleParameterizedNode(t *testing.T) {
}
}
+func Test_SingleNodeParameterizedNamed(t *testing.T) {
+ node := mustNewLeaderNode()
+ defer node.Deprovision()
+
+ tests := []struct {
+ stmt []interface{}
+ expected string
+ execute bool
+ }{
+ {
+ stmt: []interface{}{"CREATE TABLE foo (id integer not null primary key, name text, age integer)"},
+ expected: `{"results":[{}]}`,
+ execute: true,
+ },
+ {
+ stmt: []interface{}{"INSERT INTO foo(name, age) VALUES(?, ?)", "fiona", 20},
+ expected: `{"results":[{"last_insert_id":1,"rows_affected":1}]}`,
+ execute: true,
+ },
+ {
+ stmt: []interface{}{"SELECT * FROM foo WHERE NAME=:name", map[string]interface{}{"name": "fiona"}},
+ expected: `{"results":[{"columns":["id","name","age"],"types":["integer","text","integer"],"values":[[1,"fiona",20]]}]}`,
+ execute: false,
+ },
+ }
+
+ for i, tt := range tests {
+ var r string
+ var err error
+ if tt.execute {
+ r, err = node.ExecuteParameterized(tt.stmt)
+ } else {
+ r, err = node.QueryParameterized(tt.stmt)
+ }
+ if err != nil {
+ t.Fatalf(`test %d failed "%s": %s`, i, tt.stmt, err.Error())
+ }
+ if r != tt.expected {
+ t.Fatalf(`test %d received wrong result "%s" got: %s exp: %s`, i, tt.stmt, r, tt.expected)
+ }
+ }
+}
+
// Test_SingleNodeSQLInjection demonstrates that using the non-parameterized API is vulnerable to
// SQL injection attacks.
func Test_SingleNodeSQLInjection(t *testing.T) {
