vektra / mockery

A mock code autogenerator for Go
https://vektra.github.io/mockery/
BSD 3-Clause "New" or "Revised" License
6.07k stars 408 forks source link

Mockery failing to run when having private repositories as dependencies #619

Open Mendes11 opened 1 year ago

Mendes11 commented 1 year ago

Description

Mockery failing with private repositories

Mockery Version


2.14.0

Golang Version

1.18.3

Installation Method

Steps to Reproduce

  1. Import from a module belonging to a private repository
  2. Run docker run -e GOPRIVATE=$GOPRIVATE -v "$HOME/.gitconfig:/root/.gitconfig" -v "$PWD:/src" -w /src vektra/mockery -r --all --dir=./pkg/app/ports --output ./pkg/app/mocks

Expected Behavior

Mocks to be generated with mockery identifying my .gitconfig which has that token@<git_url>.insteadof <git_url>

Actual Behavior

09 May 23 12:23 UTC INF Starting mockery dry-run=false version=v2.14.0
09 May 23 12:23 UTC INF Walking dry-run=false version=v2.14.0
09 May 23 12:23 UTC ERR Error parsing file error="/src/pkg/app/ports/licenserepository.go:6:2: could not import <package_path> (invalid package name: \"\")" dry-run=false version=v2.14.0
09 May 23 12:23 UTC ERR Error parsing file error="/src/pkg/app/ports/licenserepository.go:6:2: could not import <package_path> (invalid package name: \"\")" dry-run=false version=v2.14.0

If I replace mockery's entrypoint to /bin/sh, then run it in iterative mode, running the following commands:

  1. apk add git
  2. go mod download
  3. mockery -r --all --dir=./pkg/app/ports --output ./pkg/app/mocks`

It works and the mocks got generated

LandonTClipp commented 1 year ago

Hi, please use the latest version of mockery to see if the problem still exists.

kramen22 commented 1 year ago

For what it's worth (I know this issue seems stale) I have this issue intermittently as well. I am currently using v2.35.3 and see the same invalid package name for my private package import. I use the .mockery.yaml style configuration and running go mod download && mockery -r usually works when mockery throws this error.

hsequeda commented 1 year ago

Same error v2.26.1.

kramen22 commented 1 year ago

For what it's worth (I know this issue seems stale) I have this issue intermittently as well. I am currently using v2.35.3 and see the same invalid package name for my private package import. I use the .mockery.yaml style configuration and running go mod download && mockery -r usually works when mockery throws this error.

After further investigation, I had an error that was caused by github not being properly configured to pull in private go repositories in the docker layer I was running mockery in, and after that was fixed this error went away. Maybe its possible to catch that error and print something more helpful?

LandonTClipp commented 1 year ago

This problem seems centered around the docker containers specifically. This is not surprising to me. We should probably document how to configure the environment inside the container to properly allow pulling from private repos. I'm sure this is some simple credential modification that needs to be done on the git level.

If anyone could share how they did this then I can look into adding it in the docs.

alexandear commented 5 days ago

@LandonTClipp seems like we can close the issue as #824 has been merged.