Code Monkey home page Code Monkey logo

Comments (13)

Shastick avatar Shastick commented on May 24, 2024 2

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 get no 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.

KennyHoang-CS avatar KennyHoang-CS commented on May 24, 2024 2

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.

LandonTClipp avatar LandonTClipp commented on May 24, 2024

Is the name of your module in go.mod the same as what you specified in .mockery.yaml?

from mockery.

hardskulls avatar hardskulls commented on May 24, 2024

Yes

from mockery.

LandonTClipp avatar LandonTClipp commented on May 24, 2024

Can you post the full results of the mockery run with debug logs?

from mockery.

hardskulls avatar hardskulls commented on May 24, 2024

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.

LandonTClipp avatar LandonTClipp commented on May 24, 2024

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.

hardskulls avatar hardskulls commented on May 24, 2024

Ok, glad to hear that.
Now I wait for the patch, and close the issue if the problem is solved, right?

from mockery.

LandonTClipp avatar LandonTClipp commented on May 24, 2024

Yeah this issue will be closed when the PR to fix it is merged.

from mockery.

LandonTClipp avatar LandonTClipp commented on May 24, 2024

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.

maard avatar maard commented on May 24, 2024

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:

github.com/vektra/mockery/v2/pkg/fixtures/buildtag/comment:

from mockery.

LandonTClipp avatar LandonTClipp commented on May 24, 2024

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.

Edenshaw avatar Edenshaw commented on May 24, 2024

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.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.