简体   繁体   English

Makefile:运行命令“go test ./...”后终止

[英]Makefile: Terminates after running commands “go test ./…”

I encountered a problem running "go test" from a makefile.我在从 makefile 运行“go test”时遇到了问题。 The idea behind all this is to start a docker container, run all tests against it and then stop & remove the container.这一切背后的想法是启动一个 docker 容器,针对它运行所有测试,然后停止并移除容器。

The container gets started and the tests run, but the last two commands (docker stop & rm) aren't executed.容器启动并运行测试,但未执行最后两个命令(docker stop 和 rm)。
Make returns this message: make: *** [test] Error 1 Make 返回此消息: make: *** [test] Error 1

Is it "go test" which terminates the makefile execution?是“go test”终止makefile执行吗?

.PHONY: up down test

up:
    docker-compose up

down:
    docker-compose down

test:
    docker run -d \
        --name dev \
        --env-file $${HOME}/go/src/test-api/testdata/dbConfigTest.env \
        -p 5432:5432 \
        -v $${HOME}/go/src/test-api/testdata/postgres:/var/lib/postgresql/data postgres
    
    # runs all tests including integration tests.
    go test ./... --tags=integration -failfast -v
    # stop and remove container
    docker stop `docker ps -aqf "name=dev"`
    docker rm `docker ps -aqf "name=dev"`

Assuming that you want the 'make test' to return the test status consider the following change to the makefile假设您希望“make test”返回测试状态,请考虑对 makefile 进行以下更改

test:
    docker run -d \
        --name dev \
        --env-file $${HOME}/go/src/test-api/testdata/dbConfigTest.env \
        -p 5432:5432 \
        -v $${HOME}/go/src/test-api/testdata/postgres:/var/lib/postgresql/data postgres
    
    # runs all tests including integration tests.
    go test ./... --tags=integration -failfast -v ; echo "$$?" > test.result
    # stop and remove container
    docker stop `docker ps -aqf "name=dev"`
    docker rm `docker ps -aqf "name=dev"
    exit $$(cat test.result)

It uses the test.result file to capture the exit code from the test它使用 test.result 文件从测试中捕获退出代码

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM