Unverified Commit b42125f3 authored by ncabatoff's avatar ncabatoff Committed by GitHub
Browse files

Write NewTestCluster logs to files, which get deleted if the test passes (#8911)

parent ed937c46
Showing with 58 additions and 4 deletions
+58 -4
......@@ -225,6 +225,7 @@ jobs:
VAULT_TOKEN= \
VAULT_DEV_ROOT_TOKEN_ID= \
VAULT_ACC= \
VAULT_TEST_LOG_DIR=/tmp/testlogs \
gotestsum --format=short-verbose --junitfile test-results/go-test/results.xml -- \
-tags "${GO_TAGS}" \
-timeout=60m \
......@@ -237,6 +238,8 @@ jobs:
path: test-results
- store_test_results:
path: test-results
- store_artifacts:
path: /tmp/testlogs
environment:
- CIRCLECI_CLI_VERSION: 0.1.5546
- GO_TAGS: ''
......@@ -298,6 +301,7 @@ jobs:
VAULT_TOKEN= \
VAULT_DEV_ROOT_TOKEN_ID= \
VAULT_ACC= \
VAULT_TEST_LOG_DIR=/tmp/testlogs \
gotestsum --format=short-verbose --junitfile test-results/go-test/results.xml -- \
-tags "${GO_TAGS}" \
-timeout=60m \
......@@ -310,6 +314,8 @@ jobs:
path: test-results
- store_test_results:
path: test-results
- store_artifacts:
path: /tmp/testlogs
environment:
- CIRCLECI_CLI_VERSION: 0.1.5546
- GO_TAGS: ''
......@@ -402,6 +408,9 @@ workflows:
# extra_flags:
# default: \"\"
# type: string
# log_dir:
# default: /tmp/testlogs
# type: string
# steps:
# - run:
# command: |
......@@ -435,6 +444,7 @@ workflows:
# 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 \\
......@@ -571,11 +581,14 @@ workflows:
# - 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
# test-go-race:
# executor: go-machine
# steps:
......@@ -583,10 +596,13 @@ workflows:
# - 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
# test-ui:
# executor: node
# resource_class: medium+
......
......@@ -3,6 +3,9 @@ parameters:
extra_flags:
type: string
default: ""
log_dir:
type: string
default: "/tmp/testlogs"
steps:
- run:
name: Run Go tests
......@@ -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 \
......
......@@ -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"
......@@ -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"
......@@ -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())
}
......@@ -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 {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment