Skip to content

Commit

Permalink
better handle flags
Browse files Browse the repository at this point in the history
Signed-off-by: tison <wander4096@gmail.com>
  • Loading branch information
tisonkun committed Oct 20, 2022
1 parent d16e1a2 commit 68abdf7
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 17 deletions.
7 changes: 2 additions & 5 deletions tests/gocase/integration/cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"bufio"
"bytes"
"context"
"flag"
"fmt"
"io"
"math"
Expand All @@ -39,16 +38,14 @@ 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
w *bufio.Writer
}

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)
Expand Down Expand Up @@ -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...)
Expand Down
36 changes: 36 additions & 0 deletions tests/gocase/util/flags.go
Original file line number Diff line number Diff line change
@@ -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
}
5 changes: 0 additions & 5 deletions tests/gocase/util/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ package util
import (
"context"
"crypto/tls"
"flag"
"fmt"
"net"
"os"
Expand All @@ -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
Expand Down
7 changes: 0 additions & 7 deletions tests/gocase/util/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down

0 comments on commit 68abdf7

Please sign in to comment.