Skip to content

Commit

Permalink
Merge branch 'chrusty-imports_for_inline_structs'
Browse files Browse the repository at this point in the history
  • Loading branch information
joefitzgerald committed Jul 8, 2019
2 parents 50a5c69 + e825033 commit 7335eed
Show file tree
Hide file tree
Showing 4 changed files with 174 additions and 0 deletions.
151 changes: 151 additions & 0 deletions fixtures/fixturesfakes/fake_inline_struct_params.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions fixtures/inline_struct_params.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package fixtures

import (
"context"
"net/http"
"time"
)

//counterfeiter:generate . InlineStructParams
type InlineStructParams interface {
DoSomething(ctx context.Context, body struct {
SomeString string
SomeStringPointer *string
SomeTime time.Time
SomeTimePointer *time.Time
HTTPRequest http.Request
}) error
}
4 changes: 4 additions & 0 deletions generator/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ func (f *Fake) addImportsFor(typ types.Type) {
return
case *types.Signature:
f.addTypesForMethod(t)
case *types.Struct:
for i := 0; i < t.NumFields(); i++ {
f.addImportsFor(t.Field(i).Type())
}
default:
log.Printf("!!! WARNING: Missing case for type %s\n", reflect.TypeOf(typ).String())
}
Expand Down
1 change: 1 addition & 0 deletions integration/roundtrip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ func runTests(useGopath bool, t *testing.T, when spec.G, it spec.S) {
t("ImportsGoHyphenPackage", "imports_go_hyphen_package.go", "", filepath.Join("go-hyphenpackage", "fixture.go"))
t("FirstInterface", "multiple_interfaces.go", "")
t("SecondInterface", "multiple_interfaces.go", "")
t("InlineStructParams", "inline_struct_params.go", "")
t("RequestFactory", "request_factory.go", "")
t("ReusesArgTypes", "reuses_arg_types.go", "")
t("SomethingWithForeignInterface", "something_remote.go", "", filepath.Join("aliased_package", "in_aliased_package.go"))
Expand Down

0 comments on commit 7335eed

Please sign in to comment.