Skip to content

Commit

Permalink
fix(generate): ensure config provider methods are unique within package
Browse files Browse the repository at this point in the history
Preparation for upcoming commit where one interface will be created
which embeds all service resource config providers.

Without this, there is a risk of method name collision, where
two different service resource config providers have the same methods.
  • Loading branch information
thall committed Oct 11, 2024
1 parent 24aef3b commit 263aee0
Show file tree
Hide file tree
Showing 28 changed files with 456 additions and 456 deletions.
4 changes: 2 additions & 2 deletions example/freight_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ type aipTests struct{}

var _ examplefreightv1.FreightServiceTestSuiteConfigProvider = &aipTests{}

func (a aipTests) ShipperTestSuiteConfig(_ *testing.T) *examplefreightv1.FreightServiceShipperTestSuiteConfig {
func (a aipTests) FreightServiceShipper(_ *testing.T) *examplefreightv1.FreightServiceShipperTestSuiteConfig {
// Returns nil to indicate that it's not ready to be tested.
return nil
}

func (a aipTests) SiteTestSuiteConfig(_ *testing.T) *examplefreightv1.FreightServiceSiteTestSuiteConfig {
func (a aipTests) FreightServiceSite(_ *testing.T) *examplefreightv1.FreightServiceSiteTestSuiteConfig {
// Returns nil to indicate that it's not ready to be tested.
return nil
}
12 changes: 6 additions & 6 deletions internal/plugin/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ func (s *serviceGenerator) generateConfigProvider(f *protogen.GeneratedFile) {
f.P("// that should be tested and how it's configured.")
f.P("type ", name, " interface {")
for _, resource := range s.resources {
resourceFx := resourceTestSuiteConfigName(s.service.Desc, resource)
resourceFx := serviceResourceName(s.service.Desc, resource)
f.P("// ", resourceFx, " should return a config, or nil, which means that the tests will be skipped.")
f.P(resourceType(resource), "TestSuiteConfig(t *", t, ") *", resourceFx, "")
f.P(resourceFx, "(t *", t, ") *", resourceTestSuiteConfigName(s.service.Desc, resource), "")
}
f.P("}")
f.P()
Expand All @@ -60,7 +60,7 @@ func (s *serviceGenerator) generateMainTestFunction(f *protogen.GeneratedFile) {
f.P("// ", funcName, " is the main entrypoint for starting the AIP tests.")
f.P("func ", funcName, "(t *", t, ",s ", serviceTestConfigProviderName(s.service.Desc), ") {")
for _, resource := range s.resources {
name := resourceTestSuiteConfigName(s.service.Desc, resource)
name := serviceResourceName(s.service.Desc, resource)
f.P("test", name, "(t, s)")
}
f.P("}")
Expand All @@ -81,12 +81,12 @@ func (s *serviceGenerator) generateTestFunctions(f *protogen.GeneratedFile) {
GoImportPath: "context",
})
for _, resource := range s.resources {
name := resourceTestSuiteConfigName(s.service.Desc, resource)
name := serviceResourceName(s.service.Desc, resource)
f.P("func test", name, "(t *", t, ",s ", serviceTestConfigProviderName(s.service.Desc), ") {")
f.P("t.Run(", strconv.Quote(resourceType(resource)), ", func(t *", t, ") {")
f.P("config := s.", resourceType(resource), "TestSuiteConfig(t)")
f.P("config := s.", serviceResourceName(s.service.Desc, resource), "(t)")
f.P("if (config == nil) {")
f.P("t.Skip(\"Method ", resourceType(resource), "TestSuiteConfig not implemented\")")
f.P("t.Skip(\"Method ", name, " not implemented\")")
f.P("}")
f.P("if (config.Service == nil) {")
f.P("t.Skip(\"Method ", name, ".Service() not implemented\")")
Expand Down
28 changes: 14 additions & 14 deletions proto/gen/einride/example/freight/v1/freight_service_aiptest.pb.go

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

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

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

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

Loading

0 comments on commit 263aee0

Please sign in to comment.