繁体   English   中英

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

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

我在从 makefile 运行“go test”时遇到了问题。 这一切背后的想法是启动一个 docker 容器,针对它运行所有测试,然后停止并移除容器。

容器启动并运行测试,但未执行最后两个命令(docker stop 和 rm)。
Make 返回此消息: make: *** [test] Error 1

是“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"`

假设您希望“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)

它使用 test.result 文件从测试中捕获退出代码

暂无
暂无

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

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