Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bug] Some import path may be lost when receiver and methods are defined in different file #178

Open
AtwoodHuang opened this issue Jan 2, 2023 · 0 comments

Comments

@AtwoodHuang
Copy link

AtwoodHuang commented Jan 2, 2023

I may find a bug for this code: some import paths may be lost when receiver and its methods are defined in different file.

Describe the bug

Some import paths may be lost when receiver and its methods are defined in different file.

How To Reproduce

File tree of my golang project:

|____field
| |____field.go
|____method.go
|____receiver.go
|____go.mod

receiver.go

package test

import "AtwoodHuang/test/field"

type Foo struct {
	Bar       string
	TestFiled field.Test
}

method.go

package test

func (*Foo) Foo(s string) error {
	return nil
}

field/field.go

package field

type Test struct {
}

Bugs

when generate test function for method Foo(s string) error, gotests miss import path for TestFiled in receiver Foo.(missing import path is AtwoodHuang/test/field)

package test

import "testing"

func TestFoo_Foo(t *testing.T) {
	type fields struct {
		Bar       string
		TestFiled field.Test
	}
	type args struct {
		s string
	}
	tests := []struct {
		name    string
		fields  fields
		args    args
		wantErr bool
	}{
		// TODO: Add test cases.
	}
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			f := &Foo{
				Bar:       tt.fields.Bar,
				TestFiled: tt.fields.TestFiled,
			}
			if err := f.Foo(tt.args.s); (err != nil) != tt.wantErr {
				t.Errorf("Foo.Foo() error = %v, wantErr %v", err, tt.wantErr)
			}
		})
	}
}

image

How To Fix

I will push a PR to fix this bug latter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant