Comments (13)
Just to chime in on this issue, I have a problem that might be related (although I'm on OS X):
- I'm trying to generate mocks for the current project that I have checked out
- when configuring the package using the module name configured in
go.mod
I getno required module provides package
(*)
This is on OS X, using mockery v2.36 and go v1.19.3
(I've been trying to use relative paths from the root of the project (ie ./path/to/package/to/mock
, which make it fail further in the process with a getting package config: unable to get map config for package: package not found in config
)
I'm not experimented enough to know if this is a configuration problem or if i found a bug :/
from mockery.
Hey @LandonTClipp Having the same issue of generating local packages via mockery with the packages config file as well. I can get around this by using the deprecated mockery V2 approach for now by using the command-line and just pass the name of the interfaced to be mocked directly.
Would this issue be fixed before mockery V3 releases?
from mockery.
Same issue on Mac OS X and mockery 2.42:
$ mockery
20 Feb 24 16:08 -05 INF Starting mockery dry-run=false version=v2.42.0
20 Feb 24 16:08 -05 INF Using config: /private/tmp/mockReview/.mockery.yaml dry-run=false version=v2.42.0
20 Feb 24 16:08 -05 ERR encountered error when loading package error="-: no required module provides package my-local.com; to add it:\n\tgo get my-local.com" dry-run=false version=v2.42.0
20 Feb 24 16:08 -05 ERR unable to parse packages error="error occurred when loading packages" dry-run=false version=v2.42.0
error occurred when loading packages
Here is the project you can test:
mockReview.zip
Side Note: If I use GitLab and not GitHub I got a different error:
mockery --log-level debug
20 Feb 24 15:56 -05 INF Starting mockery dry-run=false version=v2.42.0
20 Feb 24 15:56 -05 INF Using config: /Users/one/Documents/git/project/.mockery.yaml dry-run=false version=v2.42.0
20 Feb 24 15:56 -05 DBG package cache is nil dry-run=false package-path=pkg/libs/my-pkg version=v2.42.0
20 Feb 24 15:56 -05 DBG config section not provided for package dry-run=false package-path=pkg/libs/my-pkg version=v2.42.0
20 Feb 24 15:56 -05 ERR encountered error when loading package error="-: package pkg/libs/my-pkg is not in std (/opt/homebrew/Cellar/go/1.21.6/libexec/src/pkg/libs/my-pkg)" dry-run=false version=v2.42.0
20 Feb 24 15:56 -05 ERR unable to parse packages error="error occurred when loading packages" dry-run=false version=v2.42.0
error occurred when loading packages
from mockery.
Is the name of your module in go.mod
the same as what you specified in .mockery.yaml
?
from mockery.
Yes
from mockery.
Can you post the full results of the mockery run with debug logs?
from mockery.
Sure.
Note that this time I used fresh, almost empty project, but result is the same.
31 Oct 23 23:33 MSK INF Starting mockery dry-run=false version=v2.36.0
31 Oct 23 23:33 MSK INF Using config: C:\Users\ThisUser\Documents\Code\MyCode\TestProjects\go_mockery_bug\.mockery.yaml dry-run=false version=v2.36.0
31 Oct 23 23:33 MSK DBG package cache is nil dry-run=false version=v2.36.0
31 Oct 23 23:33 MSK DBG discovering sub-packages dry-run=false package-path=go_mockery_bug version=v2.36.0
31 Oct 23 23:33 MSK DBG subdirectory has a .go file, adding this path to packages config dry-run=false package-path=go_mockery_bug path="C:\\Users\\ThisUser\\Documents\\Code\\go_mockery_bug\\application\\service\\user_service\\repository" version=v2.36.0
31 Oct 23 23:33 MSK DBG subdirectory has a .go file, adding this path to packages config dry-run=false package-path=go_mockery_bug path="C:\\Users\\ThisUser\\Documents\\Code\\go_mockery_bug\\application\\service\\user_service" version=v2.36.0
31 Oct 23 23:33 MSK DBG adding sub-package config dry-run=false package-path=go_mockery_bug sub-package="go_mockery_bug\\application/service/user_service/repository" version=v2.36.0
31 Oct 23 23:33 MSK DBG adding sub-package config dry-run=false package-path=go_mockery_bug sub-package="go_mockery_bug\\application/service/user_service" version=v2.36.0
31 Oct 23 23:34 MSK DBG found file dry-run=false file="C:\\Users\\ThisUser\\Documents\\Code\\go_mockery_bug\\application\\service\\user_service\\user.go" package=go_mockery_bug/application/service/user_service version=v2.36.0
31 Oct 23 23:34 MSK DBG found file dry-run=false file="C:\\Users\\ThisUser\\Documents\\Code\\go_mockery_bug\\main.go" package=go_mockery_bug version=v2.36.0
31 Oct 23 23:34 MSK DBG found file dry-run=false file="C:\\Users\\ThisUser\\Documents\\Code\\go_mockery_bug\\application\\service\\user_service\\repository\\user_repo.go" package=go_mockery_bug/application/service/user_service/repository version=v2.36.0
31 Oct 23 23:34 MSK INF done parsing, loading dry-run=false version=v2.36.0
31 Oct 23 23:34 MSK INF done loading, visiting interface nodes dry-run=false version=v2.36.0
getting package config: unable to get map config for package: package not found in config
goroutine 1 [running]:
runtime/debug.Stack()
C:/Program Files/Go/src/runtime/debug/stack.go:24 +0x5e
github.com/vektra/mockery/v2/pkg/stackerr.NewStackErr(...)
C:/Users/ThisUser/go/pkg/mod/github.com/vektra/mockery/[email protected]/pkg/stackerr/stackerr.go:17
github.com/vektra/mockery/v2/pkg/stackerr.NewStackErrf({0x1499780?, 0xc00010a690}, {0x13d60b9?, 0xc0004d9b00?}, {0x0?, 0x0?, 0x30?})
C:/Users/ThisUser/go/pkg/mod/github.com/vektra/mockery/[email protected]/pkg/stackerr/stackerr.go:24 +0xb8
github.com/vektra/mockery/v2/pkg/config.(*Config).GetPackageConfig(0xc00025e000, {0x149d7c8, 0xc0004fa030}, {0xc0004d9b00, 0x3a})
C:/Users/ThisUser/go/pkg/mod/github.com/vektra/mockery/[email protected]/pkg/config/config.go:234 +0x425
github.com/vektra/mockery/v2/pkg/config.(*Config).ShouldGenerateInterface(0x149af80?, {0x149d7c8, 0xc0004fa030}, {0xc0004d9b00, 0x3a}, {0xc0004b6e78, 0x8})
C:/Users/ThisUser/go/pkg/mod/github.com/vektra/mockery/[email protected]/pkg/config/config.go:264 +0x49
github.com/vektra/mockery/v2/cmd.(*RootApp).Run(0xc00025e000)
C:/Users/ThisUser/go/pkg/mod/github.com/vektra/mockery/[email protected]/cmd/mockery.go:261 +0x1de6
github.com/vektra/mockery/v2/cmd.NewRootCmd.func1(0xc00021a500?, {0x13a3b64?, 0x4?, 0x13a3b68?})
C:/Users/ThisUser/go/pkg/mod/github.com/vektra/mockery/[email protected]/cmd/mockery.go:46 +0x45
github.com/spf13/cobra.(*Command).execute(0xc0001b2600, {0xc00011c050, 0x2, 0x3})
C:/Users/ThisUser/go/pkg/mod/github.com/spf13/[email protected]/command.go:920 +0x863
github.com/spf13/cobra.(*Command).ExecuteC(0xc0001b2600)
C:/Users/ThisUser/go/pkg/mod/github.com/spf13/[email protected]/command.go:1044 +0x3a5
github.com/spf13/cobra.(*Command).Execute(...)
C:/Users/ThisUser/go/pkg/mod/github.com/spf13/[email protected]/command.go:968
github.com/vektra/mockery/v2/cmd.Execute()
C:/Users/ThisUser/go/pkg/mod/github.com/vektra/mockery/[email protected]/cmd/mockery.go:104 +0x18
main.main()
C:/Users/ThisUser/go/pkg/mod/github.com/vektra/mockery/[email protected]/main.go:8 +0xf
from mockery.
Okay I think I know the issue. It's coming from the fact that mockery is registering the sub package as
go_mockery_bug\\application/service/user_service/repository
Notice the backslash. This appears to be a bug with how mockery joins paths on Windows. I'll need a patch to my pathlib package to override the separator value, which defaults to the system path separator.
from mockery.
Ok, glad to hear that.
Now I wait for the patch, and close the issue if the problem is solved, right?
from mockery.
Yeah this issue will be closed when the PR to fix it is merged.
from mockery.
when configuring the package using the module name configured in go.mod I get no required module provides package(*)
This sounds like a parsing error, perhaps some required dependency is missing in your go.mod
file.
(I've been trying to use relative paths from the root of the project (ie ./path/to/package/to/mock, which make it fail further in the process with a getting package config: unable to get map config for package: package not found in config)
I don't believe this would ever work, packages have to be specified by their fully qualified name.
from mockery.
I have the same issue as @Shastick and @KennyHoang-CS when trying to upgrade to the packages feature. When i put
packages:
github.com/MyOrg/my-package
(the name of the package matches the name in go.mod
), i receive
ERR encountered error when loading package error="-: no required module provides package github.com/MyOrg/my-package; to add it:\n\tgo get github.com/MyOrg/my-package" dry-run=false version=v2.40.1
.
So i have to resort to the approach we use currently, which worked for a long time: annotate each mocked interface with //go:generate mockery --name Name
and running go generate ./...
.
When i compare my setup with the mockery project itself, nothing stands out, except the fact that .mockery.yaml
in vektra/mockery
does not have an entry for the github.com/vektra/mockery/v2
itself, only for several sub-packages:
Line 9 in 4854efd
from mockery.
I am not going to be able to debug these various situations. What would be more helpful is if someone could provide a reproducer for me, that way I can narrow down where the issue is.
from mockery.
Related Issues (20)
- Feature Request: Infer Local Package During Generation HOT 1
- Question: MinTimes(), MaxTimes() HOT 1
- pathlib values undefined HOT 3
- Generated Mock Importing Non-Existent 'command-line-arguments' Package HOT 2
- Option to replace a generic type parameter with a specific type HOT 3
- Should 2.39.1 enough to generate mocks for 2.40.1 HOT 7
- Mockery mistakenly imports internal packages when running the 'mockery' command HOT 2
- error: package "context" without types was imported
- mockery built with go 1.22~rc2 fails HOT 6
- Running mockery with docker does not work with go 1.22
- Could not run the latest Mockery Docker image with 1.22 codebase HOT 1
- Investigate if we can use `GODEBUG=gotypealias=1` to get around type alias sadness HOT 2
- Logging warning when mock config is orphaned HOT 1
- Variadic function issues. HOT 10
- Files being created even with `dry-run: true` HOT 1
- Discussion: is interface just for mocking a good idea? HOT 1
- Configuration option `inpackage` is not functioning as expected HOT 3
- Incorrect mocks generated when there are multiple interfaces in the same package HOT 6
- Indirect dependency from go-viper includes critical vulnerability CVE-2021-28235
- Using exclude on windows throws an error because of path separator being used, I have raised a PR
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mockery.