golang / mock

GoMock is a mocking framework for the Go programming language.
Apache License 2.0
9.26k stars 608 forks source link

Inconsistent import names between Docker environments #651

Open KenxinKun opened 2 years ago

KenxinKun commented 2 years ago

Actual behavior

We have a Docker image running mockgen 1.6.0 that we use both as a "CLI tool" locally and inside our CI/CD pipelines. When running the same command both in Gitlab CI and my Mac M1 (arm64) the import paths differ. For example:

If running in Gitlab CI's Docker or directly outside Docker on my Mac M1 I get the import named with the "package name":

api "http://gitlab.com/[...]/goclient"

Instead if I run the same Docker image on my Mac M1, I get the import names after the "directory name": goclient "http://gitlab.com/[...]/goclient"

Expected behavior

The imports should be named the same in all environments (no preference on which).

To Reproduce

Minimal Dockerfile used:

ARG GO_VERSION=1.17.6
ARG GO_MOCKGEN_VERSION=v1.6.0

FROM golang:${GO_VERSION}
RUN go install github.com/golang/mock/mockgen@${GO_MOCKGEN_VERSION}

# Run version checks
RUN go version; \
    mockgen --version

WORKDIR /app

Minimal bash script we use:

#!/bin/bash
set -e

FILES=$(find ./gen/goclient -name '*.go')
mkdir -p gen/go_mock

for f in $FILES; do
  FILE=$(echo "$f" | sed "s/\//_/g" | sed "s/._gen_go//g")
  # echo "$f $FILE"
    if grep -q "interface {"'$' $f; then 
    mockgen -package mockapi -source $f -destination "gen/go_mock/$FILE"
    fi
done

Additional Information

Triage Notes for the Maintainers