Skip to content

import cycle if i write a test for the faked interface in the package of the interface #121

@dionysius

Description

@dionysius

Related to #103, but with the difference, that i'm ok with having the fake in a sub-package (omitting -o flag)

package abc
//go:generate $GOPATH/src/github.com/maxbrunsfeld/counterfeiter/counterfeiter . Foo

// some struct which the implementer of the interface should return
type Stuff struct{}

type Foo interface {
	Bar() Stuff
}

I write a test file in the same package abc

package abc

import (
	"testing"
        "github.com/where/is/abc/abcfakes"
)

func Test_SomethingInteractingWithFoo(t *testing.T) {
  // fmt.Println("some stuff happens before")
  fakeFoo := &abcfakes.FakeFoo{}
  // fmt.Println("some stuff happens after")
}

once generated, abcfakes/fake_foo.go has these lines:

// Code generated by counterfeiter. DO NOT EDIT.
package abcfakes

import (
	"sync"

	"github.com/where/is/abc"
)

// ...

func (fake *FakeFoo) Bar() (abc.Stuff) {
	// and for any other method using a type from the package
	// ...
}

// ...

var _ abc.Foo = new(FakeFoo)
  1. So, first problem is the same as in Interface fakes generated in the same package as the interface cause an import cycle #103. var _ abc.Foo = new(FakeFoo) forces the FakeFoo file to import github.com/where/is/abc which causes an import cycle, because coming from abc i'm importing github.com/where/is/abc/abcfakes.

  2. Independent of the first problem, we have still another one: func (fake *FakeFoo) Bar() (abc.Stuff) { ... } forces the FakeFoo file to import github.com/where/is/abc too, which causes an import cycle for the same reason.

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