Skip to content

Missing package in generated fakes with go.mod version at 1.23 #298

Open
@nginx-nickc

Description

Similar to #297, seeing different results with go.mod set to 1.22 vs 1.23.

package service

import (
	"context"
	"google.golang.org/protobuf/proto"

)

//go:generate go run github.com/maxbrunsfeld/counterfeiter/v6 -generate

//counterfeiter:generate . Example
type Example interface {
	FindExample(context.Context, proto.Message) ([]string, error)
}

with following go.mod file

module foo

go 1.22.0

toolchain go1.23.1

require google.golang.org/protobuf v1.34.2

require (
	github.com/google/go-cmp v0.6.0 // indirect
	github.com/maxbrunsfeld/counterfeiter/v6 v6.9.0 // indirect
	golang.org/x/mod v0.21.0 // indirect
	golang.org/x/sync v0.8.0 // indirect
	golang.org/x/text v0.18.0 // indirect
	golang.org/x/tools v0.25.0 // indirect
)

getting, works, but not quite correct.

package examplefakes

import (
        "context"
        service "foo"
        "sync"

        "google.golang.org/protobuf/reflect/protoreflect"
)

type FakeExample struct {
        FindExampleStub        func(context.Context, protoreflect.ProtoMessage) ([]string, error)
        findExampleMutex       sync.RWMutex
        findExampleArgsForCall []struct {
                arg1 context.Context
                arg2 protoreflect.ProtoMessage
        }

when change go.mod to

module foo

go 1.23.1

require google.golang.org/protobuf v1.34.2

require (
        github.com/google/go-cmp v0.6.0 // indirect
        github.com/maxbrunsfeld/counterfeiter/v6 v6.9.0 // indirect
        golang.org/x/mod v0.21.0 // indirect
        golang.org/x/sync v0.8.0 // indirect
        golang.org/x/text v0.18.0 // indirect
        golang.org/x/tools v0.25.0 // indirect
)

getting the following, which is causing errors.

package examplefakes

import (
        "context"
        service "foo"
        "sync"
)

type FakeExample struct {
        FindExampleStub        func(context.Context, Message) ([]string, error)
        findExampleMutex       sync.RWMutex
        findExampleArgsForCall []struct {
                arg1 context.Context
                arg2 Message
        }
        findExampleReturns struct {

Looks like possible work around

GODEBUG=gotypesalias=0 go generate ./...

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions