dongli4711 2018-11-26 10:53
浏览 558
已采纳

如何禁用CGO进行测试

I use Docker to add my project to it, now I want to run some test on it and I got errors that the test failed

Any idea what I miss here?

# build stage
FROM golang:1.11.1-alpine3.8 AS builder

RUN apk add --update --no-cache make \
    git

ADD https://github.com/golang/dep/releases/download/v0.5.0/dep-linux-amd64 /usr/bin/dep
RUN chmod +x /usr/bin/dep

RUN mkdir -p $GOPATH/src/github.company/user/go-application
WORKDIR  $GOPATH/src/github.company/user/go-application
COPY Gopkg.toml Gopkg.lock ./
RUN dep ensure --vendor-only
COPY . ./

Now I build the docker which finish successfully and now I want to run tests on it.

I did docker run docker run -it goapp which run successfully

And now I use command go test -v ./... and I got error

# runtime/cgo
exec: "gcc": executable file not found in $PATH
FAIL    github.company/user/go-application [build failed]
FAIL    github.company/user/go-application/integration [build failed]

Any idea how to resolve this ?

I try another step in docker file like following which doesnt helps

RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix nocgo -o /go-application .
  • 写回答

1条回答 默认 最新

  • douzong6649 2018-11-26 11:06
    关注

    You've disabled CGO for your build, but you're not disabling CGO for your tests, which you must do:

    CGO_ENABLED=0 GOOS=linux go test -v ./...
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算