1
1
package gocql
2
2
3
3
import (
4
- "flag"
5
4
"fmt"
5
+ "github.com/gocql/gocql/internal/testcmdline"
6
6
"log"
7
7
"net"
8
8
"reflect"
@@ -12,39 +12,20 @@ import (
12
12
"time"
13
13
)
14
14
15
- var (
16
- flagCluster = flag .String ("cluster" , "127.0.0.1" , "a comma-separated list of host:port tuples" )
17
- flagMultiNodeCluster = flag .String ("multiCluster" , "127.0.0.2" , "a comma-separated list of host:port tuples" )
18
- flagProto = flag .Int ("proto" , 0 , "protcol version" )
19
- flagCQL = flag .String ("cql" , "3.0.0" , "CQL version" )
20
- flagRF = flag .Int ("rf" , 1 , "replication factor for test keyspace" )
21
- clusterSize = flag .Int ("clusterSize" , 1 , "the expected size of the cluster" )
22
- flagRetry = flag .Int ("retries" , 5 , "number of times to retry queries" )
23
- flagAutoWait = flag .Duration ("autowait" , 1000 * time .Millisecond , "time to wait for autodiscovery to fill the hosts poll" )
24
- flagRunSslTest = flag .Bool ("runssl" , false , "Set to true to run ssl test" )
25
- flagRunAuthTest = flag .Bool ("runauth" , false , "Set to true to run authentication test" )
26
- flagCompressTest = flag .String ("compressor" , "" , "compressor to use" )
27
- flagTimeout = flag .Duration ("gocql.timeout" , 5 * time .Second , "sets the connection `timeout` for all operations" )
28
-
29
- flagCassVersion cassVersion
30
- )
31
-
32
15
func init () {
33
- flag .Var (& flagCassVersion , "gocql.cversion" , "the cassandra version being tested against" )
34
-
35
16
log .SetFlags (log .Lshortfile | log .LstdFlags )
36
17
}
37
18
38
19
func getClusterHosts () []string {
39
- return strings .Split (* flagCluster , "," )
20
+ return strings .Split (* testcmdline . Cluster , "," )
40
21
}
41
22
42
23
func getMultiNodeClusterHosts () []string {
43
- return strings .Split (* flagMultiNodeCluster , "," )
24
+ return strings .Split (* testcmdline . MultiNodeCluster , "," )
44
25
}
45
26
46
27
func addSslOptions (cluster * ClusterConfig ) * ClusterConfig {
47
- if * flagRunSslTest {
28
+ if * testcmdline . RunSslTest {
48
29
cluster .Port = 9142
49
30
cluster .SslOpts = & SslOptions {
50
31
CertPath : "testdata/pki/gocql.crt" ,
@@ -81,21 +62,21 @@ func createTable(s *Session, table string) error {
81
62
func createCluster (opts ... func (* ClusterConfig )) * ClusterConfig {
82
63
clusterHosts := getClusterHosts ()
83
64
cluster := NewCluster (clusterHosts ... )
84
- cluster .ProtoVersion = * flagProto
85
- cluster .CQLVersion = * flagCQL
86
- cluster .Timeout = * flagTimeout
65
+ cluster .ProtoVersion = * testcmdline . Proto
66
+ cluster .CQLVersion = * testcmdline . CQL
67
+ cluster .Timeout = * testcmdline . Timeout
87
68
cluster .Consistency = Quorum
88
69
cluster .MaxWaitSchemaAgreement = 2 * time .Minute // travis might be slow
89
- if * flagRetry > 0 {
90
- cluster .RetryPolicy = & SimpleRetryPolicy {NumRetries : * flagRetry }
70
+ if * testcmdline . Retry > 0 {
71
+ cluster .RetryPolicy = & SimpleRetryPolicy {NumRetries : * testcmdline . Retry }
91
72
}
92
73
93
- switch * flagCompressTest {
74
+ switch * testcmdline . CompressTest {
94
75
case "snappy" :
95
76
cluster .Compressor = & SnappyCompressor {}
96
77
case "" :
97
78
default :
98
- panic ("invalid compressor: " + * flagCompressTest )
79
+ panic ("invalid compressor: " + * testcmdline . CompressTest )
99
80
}
100
81
101
82
cluster = addSslOptions (cluster )
@@ -110,21 +91,21 @@ func createCluster(opts ...func(*ClusterConfig)) *ClusterConfig {
110
91
func createMultiNodeCluster (opts ... func (* ClusterConfig )) * ClusterConfig {
111
92
clusterHosts := getMultiNodeClusterHosts ()
112
93
cluster := NewCluster (clusterHosts ... )
113
- cluster .ProtoVersion = * flagProto
114
- cluster .CQLVersion = * flagCQL
115
- cluster .Timeout = * flagTimeout
94
+ cluster .ProtoVersion = * testcmdline . Proto
95
+ cluster .CQLVersion = * testcmdline . CQL
96
+ cluster .Timeout = * testcmdline . Timeout
116
97
cluster .Consistency = Quorum
117
98
cluster .MaxWaitSchemaAgreement = 2 * time .Minute // travis might be slow
118
- if * flagRetry > 0 {
119
- cluster .RetryPolicy = & SimpleRetryPolicy {NumRetries : * flagRetry }
99
+ if * testcmdline . Retry > 0 {
100
+ cluster .RetryPolicy = & SimpleRetryPolicy {NumRetries : * testcmdline . Retry }
120
101
}
121
102
122
- switch * flagCompressTest {
103
+ switch * testcmdline . CompressTest {
123
104
case "snappy" :
124
105
cluster .Compressor = & SnappyCompressor {}
125
106
case "" :
126
107
default :
127
- panic ("invalid compressor: " + * flagCompressTest )
108
+ panic ("invalid compressor: " + * testcmdline . CompressTest )
128
109
}
129
110
130
111
cluster = addSslOptions (cluster )
@@ -156,7 +137,7 @@ func createKeyspace(tb testing.TB, cluster *ClusterConfig, keyspace string) {
156
137
WITH replication = {
157
138
'class' : 'SimpleStrategy',
158
139
'replication_factor' : %d
159
- }` , keyspace , * flagRF ))
140
+ }` , keyspace , * testcmdline . RF ))
160
141
161
142
if err != nil {
162
143
panic (fmt .Sprintf ("unable to create keyspace: %v" , err ))
@@ -232,7 +213,7 @@ func createViews(t *testing.T, session *Session) {
232
213
}
233
214
234
215
func createMaterializedViews (t * testing.T , session * Session ) {
235
- if flagCassVersion .Before (3 , 0 , 0 ) {
216
+ if testcmdline . CassVersion .Before (3 , 0 , 0 ) {
236
217
return
237
218
}
238
219
if err := session .Query (`CREATE TABLE IF NOT EXISTS gocql_test.view_table (
0 commit comments