Skip to content

Commit

Permalink
Add an option to pass environment variables to the start command
Browse files Browse the repository at this point in the history
  • Loading branch information
rafiss committed Nov 14, 2022
1 parent 72ccb42 commit 73661a2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*~
.#*
*.test
testserver/cockroach-data/
9 changes: 9 additions & 0 deletions testserver/testserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ type testServerArgs struct {
externalIODir string
initTimeoutSeconds int
pollListenURLTimeoutSeconds int
envVars []string // to be passed to cmd.Env
}

// CockroachBinaryPathOpt is a TestServer option that can be passed to
Expand Down Expand Up @@ -366,6 +367,14 @@ func PollListenURLTimeoutOpt(timeout int) TestServerOpt {
}
}

// EnvVarOpt is a list of environment variables to be passed to the start
// command. Each entry in the slice should be in `key=value` format.
func EnvVarOpt(vars []string) TestServerOpt {
return func(args *testServerArgs) {
args.envVars = vars
}
}

const (
logsDirName = "logs"
certsDirName = "certs"
Expand Down
1 change: 1 addition & 0 deletions testserver/testservernode.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func (ts *testServerImpl) StartNode(i int) error {
"COCKROACH_MAX_OFFSET=1ns",
"COCKROACH_TRUST_CLIENT_PROVIDED_SQL_REMOTE_ADDR=true",
}
currCmd.Env = append(currCmd.Env, ts.serverArgs.envVars...)

// Set the working directory of the cockroach process to our temp folder.
// This stops cockroach from polluting the project directory with _dump
Expand Down

0 comments on commit 73661a2

Please sign in to comment.