我正在使用docker-compose服务运行Go测试。我的测试失败时,我想使容器失败或构建。但是现在,当Go-tests失败时,docker容器会显示pr_validator_tests_1 exited with code 0
不正确。
tests_1 | FAIL go-testing-framework/tests 0.029s
tests_1 | FAIL
pr_validator_tests_1 exited with code 0
我正在使用以下命令运行docker-compose文件:
docker-compose up --abort-on-container-exit --exit-code-from test
这就是我运行测试套件的方式。
func TestIntegration(t *testing.T) {
suite.Run(t, new(TestSuite))
}
测试断言:
if !s.Equal(expectedCode, response.StatusCode) {
s.T().Error(message)
return
}
docker-compose.yml文件
version: '3'
services:
integration:
build:
context: ./
dockerfile: Dockerfile
healthcheck:
test: ["CMD", "nc", "localhost", "3000"]
environment:
- some envies
container_name: integration
ports:
- 3000:3000
mockservice:
image: mock:latest
environment:
- some envies
ports:
- 8801:8801
tests:
image: go-testing-framework:latest
environment:
- URL=http://integration:3000
- and some envies
links:
- integration
depends_on:
- integration
- mockservice
是否可以不使用Jenkins插件或使用golang代码使Jenkins构建失败?
最佳答案
我在make命令的末尾添加了||exit 1
,还添加了一个Shell脚本来检索退出代码。
#!/bin/bash
make test
status=$?
if [[ $status != 0 ]]; then
echo "exit code for test: " $status
exit $status
fi
如果测试失败,此脚本将终止容器
关于docker - Go测试失败时停止docker容器服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60335832/