Skip to content

Pegomock resolves real type instead of alias type #117

@jpopadak

Description

@jpopadak

Creating Pegomock Matchers or Mocks for a type which is an alias for a private ./internal/ package type causes compile errors upon matcher creation.

Setup
In the example below, status.Status is a type alias denoted here in their code.

File: ./myfile.go

package mypkg

import (
	"google.golang.org/grpc/status"
)

//go:generate ${PEGOMOCK} generate -m mypkg MyInterface

type MyInterface interface {
	MyFunction(s *status.Status)
}

Result
When generating a matcher, it instead generates a file using the ./internal/. package path instead of the public one.

The resulting matcher file has this header, referencing the internal package.
File: ./matchers/ptr_to_status_status.go

// Code generated by pegomock. DO NOT EDIT.
package matchers

import (
	"github.com/petergtz/pegomock"
	"reflect"

	status "google.golang.org/grpc/internal/status"
)

// ... more Matcher code

The same occurs for the Mock itself.
File: ./mock_myinterface_test.go

// Code generated by pegomock. DO NOT EDIT.
// Source: mypkg (interfaces: MyInterface)

package mypkg_test

import (
	pegomock "github.com/petergtz/pegomock"
	status "google.golang.org/grpc/internal/status"
	"reflect"
	"time"
)

// ... more Matcher code

Thoughts
Is this a limitation around how the types are resolved? Or do we try to find the alias type to place in here?

Metadata

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