From 6ca5e2ae91a0126db14d735aae74665af3243c34 Mon Sep 17 00:00:00 2001 From: Serhii Polishchuk Date: Fri, 31 Dec 2021 11:55:37 +0200 Subject: [PATCH] gocqlxtest: add test keyspace name flag --- gocqlxtest/gocqlxtest.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/gocqlxtest/gocqlxtest.go b/gocqlxtest/gocqlxtest.go index 6a9524f..6272d59 100644 --- a/gocqlxtest/gocqlxtest.go +++ b/gocqlxtest/gocqlxtest.go @@ -18,6 +18,7 @@ import ( var ( flagCluster = flag.String("cluster", "127.0.0.1", "a comma-separated list of host:port tuples") + flagKeyspace = flag.String("keyspace", "gocqlx_test", "keyspace name") flagProto = flag.Int("proto", 0, "protcol version") flagCQL = flag.String("cql", "3.0.0", "CQL version") flagRF = flag.Int("rf", 1, "replication factor for test keyspace") @@ -92,15 +93,18 @@ func CreateKeyspace(cluster *gocql.ClusterConfig, keyspace string) error { } func createSessionFromCluster(cluster *gocql.ClusterConfig, tb testing.TB) gocqlx.Session { + if !flag.Parsed() { + flag.Parse() + } // Drop and re-create the keyspace once. Different tests should use their own // individual tables, but can assume that the table does not exist before. initOnce.Do(func() { - if err := CreateKeyspace(cluster, "gocqlx_test"); err != nil { + if err := CreateKeyspace(cluster, *flagKeyspace); err != nil { tb.Fatal(err) } }) - cluster.Keyspace = "gocqlx_test" + cluster.Keyspace = *flagKeyspace session, err := gocqlx.WrapSession(cluster.CreateSession()) if err != nil { tb.Fatal("CreateSession:", err)