vektra / mockery

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

Impossible to generate mocks with package bwmarrin/discordgo #361

Closed jokaorgua closed 1 year ago

jokaorgua commented 3 years ago

Hello. I wasn't able to create mocks for the interface

import "github.com/bwmarrin/discordgo"

type ChannelSendMessageInterface interface {
    ChannelMessageSend(channel string, content string) (*discordgo.Message, error)
}

I run

docker run -v "path_to_projects/go/src":/go/src -v "path_to_projects/go/src/project":/go/src/project -w /src vektra/mockery:latest --all --keeptree  --recursive --log-level debug --dir /go/src/project --output /go/src/project/Tests/mocks

and get the following log

01 Feb 21 14:13 UTC ERR Error parsing file error="/go/src/project/channel_send_message_interface.go:3:8: could not import github.com/bwmarrin/discordgo (invalid package name: \"\")" dry-run=false version=2.5.1

any ideas on how to fix that?

LandonTClipp commented 3 years ago

Does the same thing happen if you run the mockery binary directly?

jokaorgua commented 3 years ago

Does the same thing happen if you run the mockery binary directly?

what do you mean? I was using a guide from the main page of this repo. Got docker image and ran it

if you mean this command go get github.com/vektra/mockery/v2/.../ I tried it. But wasn't able to locate the binary after getting the package

if you mean standalone binary so I tried to download 2.5.1 and ran it. Everything is ok. Works as should I've used this command ./mockery --all --keeptree --recursive --log-level debug --dir ./ --output ./Tests/mocks

xmlking commented 3 years ago

same with "github.com/go-resty/resty/v2" package. nothing generated.

lcd1232 commented 3 years ago

@LandonTClipp same error

package account

import (
    "github.com/pkg/errors"
)

var ErrSessionNotFound = errors.New("account: session not found")

I'm using go generate //go:generate mockery --dir "." --case "underscore" --outpkg "accountmocks" --output "../../internal/mocks/accountmocks" --all

02 Apr 21 13:11 MSK INF Starting mockery dry-run=false version=v2.7.4
02 Apr 21 13:11 MSK INF Walking dry-run=false version=v2.7.4
02 Apr 21 13:11 MSK ERR Error parsing file error="/Users/lcd1232/Projects/project/pkg/account/session.go:4:2: could not import github.com/pkg/errors (invalid package name: \"\")" dry-run=false version=v2.7.4
lcd1232 commented 3 years ago

Looks like it's a problem with go 1.16, I tried 1.15 and it works fine

LandonTClipp commented 1 year ago

Closing out this old ticket, if this still occurs with the latest version of mockery and golang please re-open.