Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion .circleci/config.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .circleci/config/commands/go_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ parameters:
extra_flags:
type: string
default: ""
log_dir:
type: string
default: "/tmp/testlogs"
steps:
- run:
name: Run Go tests
Expand Down Expand Up @@ -38,6 +41,7 @@ steps:
VAULT_TOKEN= \
VAULT_DEV_ROOT_TOKEN_ID= \
VAULT_ACC= \
VAULT_TEST_LOG_DIR=<< parameters.log_dir >> \
gotestsum --format=short-verbose --junitfile test-results/go-test/results.xml -- \
-tags "${GO_TAGS}" \
-timeout=60m \
Expand Down
3 changes: 3 additions & 0 deletions .circleci/config/jobs/test-go-race.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ steps:
- checkout
- go_test:
extra_flags: "-race"
log_dir: "/tmp/testlogs"
- store_artifacts:
path: test-results
- store_test_results:
path: test-results
- store_artifacts:
path: "/tmp/testlogs"
5 changes: 4 additions & 1 deletion .circleci/config/jobs/test-go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ steps:
- check-branch-name
- setup-go
- checkout
- go_test
- go_test:
log_dir: "/tmp/testlogs"
- store_artifacts:
path: test-results
- store_test_results:
path: test-results
- store_artifacts:
path: "/tmp/testlogs"
32 changes: 30 additions & 2 deletions vault/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -1132,9 +1132,30 @@ func NewTestCluster(t testing.T, base *CoreConfig, opts *TestClusterOptions) *Te

var testCluster TestCluster

if opts != nil && opts.Logger != nil {
var logDir = os.Getenv("VAULT_TEST_LOG_DIR")
var logFileName string
var logFile *os.File

switch {
case opts != nil && opts.Logger != nil:
testCluster.Logger = opts.Logger
} else {
case logDir != "":
// This is not ideal because t.Name does not include the package, and
// there's no easy way to get it. However, at present there aren't many
// tests that have the same name, and from what I can see there are no
// duplicates that call NewTestCluster.
logFileName = filepath.Join(logDir, t.Name()+".log")
// t.Name may include slashes.
dir, _ := filepath.Split(logFileName)
if err := os.MkdirAll(dir, 0755); err != nil {
t.Fatal(err)
}
logFile, err = os.Create(logFileName)
if err != nil {
t.Fatal(err)
}
testCluster.Logger = logging.NewVaultLoggerWithWriter(logFile, log.Trace)
default:
testCluster.Logger = logging.NewVaultLogger(log.Trace).Named(t.Name())
}

Expand Down Expand Up @@ -1789,6 +1810,13 @@ func NewTestCluster(t testing.T, base *CoreConfig, opts *TestClusterOptions) *Te
for _, c := range cleanupFuncs {
c()
}
if logFile != nil {
if t.Failed() {
logFile.Close()
} else {
os.Remove(logFileName)
}
}
}
if opts != nil {
if opts.SetupFunc != nil {
Expand Down