dongli4711
dongli4711
2018-11-26 10:53
浏览 152

如何禁用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
    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 ./...
    
    点赞 评论

相关推荐