فهرست منبع

Refactor reprepare statement tests

Nimi Wariboko Jr 11 سال پیش
والد
کامیت
11820ec241
1فایلهای تغییر یافته به همراه13 افزوده شده و 40 حذف شده
  1. 13 40
      cassandra_test.go

+ 13 - 40
cassandra_test.go

@@ -573,18 +573,15 @@ func TestScanCASWithNilArguments(t *testing.T) {
 	}
 }
 
-func TestReprepareStatement(t *testing.T) {
-	session := createSession(t)
-	defer session.Close()
-
-	if err := session.Query(`CREATE TABLE test_reprepare_statement (
+func injectInvalidPreparedStatement(t *testing.T, session *Session, table string) (string, *Conn) {
+	if err := session.Query(`CREATE TABLE ` + table + ` (
 			foo   varchar,
 			bar   int,
 			PRIMARY KEY (foo, bar)
 	)`).Exec(); err != nil {
 		t.Fatal("create:", err)
 	}
-	stmt := "INSERT INTO test_reprepare_statement (foo, bar) VALUES (?, 7)"
+	stmt := "INSERT INTO " + table + " (foo, bar) VALUES (?, 7)"
 	conn := session.Pool.Pick(nil)
 	conn.prepMu.Lock()
 	flight := new(inflightPrepare)
@@ -593,14 +590,14 @@ func TestReprepareStatement(t *testing.T) {
 		id: []byte{'f', 'o', 'o', 'b', 'a', 'r'},
 		args: []ColumnInfo{ColumnInfo{
 			Keyspace: "gocql_test",
-			Table:    "test_reprepare_statement",
+			Table:    table,
 			Name:     "foo",
 			TypeInfo: &TypeInfo{
 				Type: TypeVarchar,
 			},
 		}, ColumnInfo{
 			Keyspace: "gocql_test",
-			Table:    "test_reprepare_statement",
+			Table:    table,
 			Name:     "bar",
 			TypeInfo: &TypeInfo{
 				Type: TypeInt,
@@ -608,6 +605,13 @@ func TestReprepareStatement(t *testing.T) {
 		}},
 	}
 	conn.prepMu.Unlock()
+	return stmt, conn
+}
+
+func TestReprepareStatement(t *testing.T) {
+	session := createSession(t)
+	defer session.Close()
+	stmt, conn := injectInvalidPreparedStatement(t, session, "test_reprepare_statement")
 	query := session.Query(stmt, "bar")
 	if err := conn.executeQuery(query).Close(); err != nil {
 		t.Fatalf("Failed to execute query for reprepare statement: %v", err)
@@ -617,38 +621,7 @@ func TestReprepareStatement(t *testing.T) {
 func TestReprepareBatch(t *testing.T) {
 	session := createSession(t)
 	defer session.Close()
-
-	if err := session.Query(`CREATE TABLE test_reprepare_statement_batch (
-			foo   varchar,
-			bar   int,
-			PRIMARY KEY (foo, bar)
-	)`).Exec(); err != nil {
-		t.Fatal("create:", err)
-	}
-	stmt := "INSERT INTO test_reprepare_statement_batch (foo, bar) VALUES (?, 7)"
-	conn := session.Pool.Pick(nil)
-	conn.prepMu.Lock()
-	flight := new(inflightPrepare)
-	conn.prep[stmt] = flight
-	flight.info = &queryInfo{
-		id: []byte{'f', 'o', 'o', 'b', 'a', 'r'},
-		args: []ColumnInfo{ColumnInfo{
-			Keyspace: "gocql_test",
-			Table:    "test_reprepare_statement_batch",
-			Name:     "foo",
-			TypeInfo: &TypeInfo{
-				Type: TypeVarchar,
-			},
-		}, ColumnInfo{
-			Keyspace: "gocql_test",
-			Table:    "test_reprepare_statement_batch",
-			Name:     "bar",
-			TypeInfo: &TypeInfo{
-				Type: TypeInt,
-			},
-		}},
-	}
-	conn.prepMu.Unlock()
+	stmt, conn := injectInvalidPreparedStatement(t, session, "test_reprepare_statement_batch")
 	batch := session.NewBatch(UnloggedBatch)
 	batch.Query(stmt, "bar")
 	if err := conn.executeBatch(batch); err != nil {