From 68abdf76596fc9d63b96274f1c5bad259bdc2ea1 Mon Sep 17 00:00:00 2001 From: tison Date: Thu, 20 Oct 2022 11:35:44 +0800 Subject: [PATCH] better handle flags Signed-off-by: tison --- tests/gocase/integration/cli/cli_test.go | 7 ++--- tests/gocase/util/flags.go | 36 ++++++++++++++++++++++++ tests/gocase/util/server.go | 5 ---- tests/gocase/util/tls.go | 7 ----- 4 files changed, 38 insertions(+), 17 deletions(-) create mode 100644 tests/gocase/util/flags.go diff --git a/tests/gocase/integration/cli/cli_test.go b/tests/gocase/integration/cli/cli_test.go index 616f86b4330..ad6d4776dfe 100644 --- a/tests/gocase/integration/cli/cli_test.go +++ b/tests/gocase/integration/cli/cli_test.go @@ -23,7 +23,6 @@ import ( "bufio" "bytes" "context" - "flag" "fmt" "io" "math" @@ -39,8 +38,6 @@ import ( const defaultByteBufLen = math.MaxUint16 -var cliPath = flag.String("cliPath", "redis-cli", "path to redis-cli") - type interactiveCli struct { c *exec.Cmd r *bufio.Reader @@ -48,7 +45,7 @@ type interactiveCli struct { } func createInteractiveCli(t *testing.T, srv *util.KvrocksServer) *interactiveCli { - c := exec.Command(*cliPath) + c := exec.Command(util.CLIPath()) c.Args = append(c.Args, "-h", srv.Host(), "-p", fmt.Sprintf("%d", srv.Port())) w, err := c.StdinPipe() require.NoError(t, err) @@ -120,7 +117,7 @@ func (res *result) Failed() { } func runCli(t *testing.T, srv *util.KvrocksServer, in io.Reader, args ...string) *result { - c := exec.Command(*cliPath) + c := exec.Command(util.CLIPath()) c.Stdin = in c.Args = append(c.Args, "-h", srv.Host(), "-p", fmt.Sprintf("%d", srv.Port())) c.Args = append(c.Args, args...) diff --git a/tests/gocase/util/flags.go b/tests/gocase/util/flags.go new file mode 100644 index 00000000000..d88583dadb6 --- /dev/null +++ b/tests/gocase/util/flags.go @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package util + +import "flag" + +var binPath = flag.String("binPath", "", "directory including kvrocks build files") +var workspace = flag.String("workspace", "", "directory of cases workspace") +var deleteOnExit = flag.Bool("deleteOnExit", false, "whether to delete workspace on exit") +var cliPath = flag.String("cliPath", "redis-cli", "path to redis-cli") +var tlsEnable = flag.Bool("tlsEnable", true, "enable TLS-related test cases") + +func CLIPath() string { + return *cliPath +} + +func TLSEnable() bool { + return *tlsEnable +} diff --git a/tests/gocase/util/server.go b/tests/gocase/util/server.go index 82941f720ef..f6c80216ee1 100644 --- a/tests/gocase/util/server.go +++ b/tests/gocase/util/server.go @@ -22,7 +22,6 @@ package util import ( "context" "crypto/tls" - "flag" "fmt" "net" "os" @@ -39,10 +38,6 @@ import ( "golang.org/x/exp/slices" ) -var binPath = flag.String("binPath", "", "directory including kvrocks build files") -var workspace = flag.String("workspace", "", "directory of cases workspace") -var deleteOnExit = flag.Bool("deleteOnExit", false, "whether to delete workspace on exit") - type KvrocksServer struct { t testing.TB cmd *exec.Cmd diff --git a/tests/gocase/util/tls.go b/tests/gocase/util/tls.go index dba26fd428a..38858ace250 100644 --- a/tests/gocase/util/tls.go +++ b/tests/gocase/util/tls.go @@ -22,17 +22,10 @@ package util import ( "crypto/tls" "crypto/x509" - "flag" "os" "path/filepath" ) -var tlsEnable = flag.Bool("tlsEnable", true, "enable TLS-related test cases") - -func TLSEnable() bool { - return *tlsEnable -} - func DefaultTLSConfig() (*tls.Config, error) { dir := filepath.Join(*workspace, "..", "tls", "cert")