登录
首页 >  Golang >  Go问答

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

来源:stackoverflow

时间:2024-04-21 19:06:36 373浏览 收藏

最近发现不少小伙伴都对Golang很感兴趣,所以今天继续给大家介绍Golang相关的知识,本文《Makefile:运行命令“go test ./...”后终止》主要内容涉及到等等知识点,希望能帮到你!当然如果阅读本文时存在不同想法,可以在评论中表达,但是请勿使用过激的措辞~

问题内容

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

容器启动并运行测试,但最后两个命令(docker stop 和 rm)未执行。

make 返回此消息: make:*** [测试]错误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 文件捕获测试的退出代码

以上就是本文的全部内容了,是否有顺利帮助你解决问题?若是能给你带来学习上的帮助,请大家多多支持golang学习网!更多关于Golang的相关知识,也可关注golang学习网公众号。

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>