vektra / mockery

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

Same name imports with numbers in the directory structure generates invalid imports #805

Closed leitzler closed 3 months ago

leitzler commented 3 months ago

Description

Same name imports with numbers in the directory structure generates invalid imports.

Mockery Version

v2.44.1

Go Version

Go tip, 49adb8e46

Installation Method

Steps to Reproduce

With a file named x.go:

package x

import (
    a "github.com/Azure/azure-sdk-for-go/services/containerservice/mgmt/2020-02-01/containerservice"
    b "github.com/Azure/azure-sdk-for-go/services/containerservice/mgmt/2020-12-01/containerservice"
)

type Foo interface {
    A(a.Resource)
    B(b.Resource)
}

Call mockery --all.

Expected Behavior

Valid Go code.

Actual Behavior

The generated import alias begins with a digit, something that isn't allowed:

Between the lines is the file (mock.go) mockery generated in-memory but detected as invalid:
--------------------------------------------------------------------------------------------
// Code generated by mockery v2.44.1. DO NOT EDIT.

package mocks

import 2020_12_01containerservice "github.com/Azure/azure-sdk-for-go/services/containerservice/mgmt/2020-12-01/containerservice"
import containerservice "github.com/Azure/azure-sdk-for-go/services/containerservice/mgmt/2020-02-01/containerservice"
import mock "github.com/stretchr/testify/mock"
import x "x"

// Foo is an autogenerated mock type for the Foo type
type Foo struct {
    mock.Mock
}

// A provides a mock function with given fields: _a0
func (_m *Foo) A(_a0 containerservice.Resource)  {_m.Called(_a0)
}

// B provides a mock function with given fields: _a0
func (_m *Foo) B(_a0 2020_12_01containerservice.Resource)  {_m.Called(_a0)
}

// NewFoo creates a new instance of Foo. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
// The first argument is typically a *testing.T value.
func NewFoo(t interface {
    mock.TestingT
    Cleanup(func())
}) *Foo {
    mock := &Foo{}
    mock.Mock.Test(t)

    t.Cleanup(func() { mock.AssertExpectations(t) })

    return mock
}

--------------------------------------------------------------------------------------------
Error walking Foo: mock.go:5:8: import path must be a string (and 1 more errors)