Skip to content

Commit

Permalink
fix: module tests can have _test package suffix (#2149)
Browse files Browse the repository at this point in the history
fixes #2141

Also added a test for a subpackage within a module to confirm that the
correct module name is derived
  • Loading branch information
matt2e authored Jul 25, 2024
1 parent 7612fea commit 037a172
Show file tree
Hide file tree
Showing 10 changed files with 175 additions and 3 deletions.
4 changes: 3 additions & 1 deletion go-runtime/ftl/ftltest/ftltest_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ func TestModuleUnitTests(t *testing.T) {
in.CopyModule("verbtypes"),
in.CopyModule("pubsub"),
in.CopyModule("subscriber"),
in.Build("time", "wrapped", "verbtypes", "pubsub", "subscriber"),
in.CopyModule("outer"),
in.Build("time", "wrapped", "verbtypes", "pubsub", "subscriber", "outer"),
in.ExecModuleTest("wrapped"),
in.ExecModuleTest("verbtypes"),
in.ExecModuleTest("pubsub"),
in.ExecModuleTest("subscriber"),
in.ExecModuleTest("outer"),
)
}
2 changes: 2 additions & 0 deletions go-runtime/ftl/ftltest/testdata/go/outer/ftl.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module = "outer"
language = "go"
24 changes: 24 additions & 0 deletions go-runtime/ftl/ftltest/testdata/go/outer/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module ftl/outer

go 1.22.2

toolchain go1.22.3

replace github.com/TBD54566975/ftl => ./../../../../../..

require (
github.com/TBD54566975/ftl v0.0.0-00010101000000-000000000000
github.com/alecthomas/assert/v2 v2.10.0
)

require (
github.com/alecthomas/participle/v2 v2.1.1 // indirect
github.com/alecthomas/repr v0.4.0 // indirect
github.com/alecthomas/types v0.16.0 // indirect
github.com/hexops/gotextdiff v1.0.3 // indirect
github.com/stretchr/testify v1.9.0 // indirect
github.com/swaggest/jsonschema-go v0.3.72 // indirect
github.com/swaggest/refl v1.3.0 // indirect
golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8 // indirect
google.golang.org/protobuf v1.34.2 // indirect
)
126 changes: 126 additions & 0 deletions go-runtime/ftl/ftltest/testdata/go/outer/go.sum

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

1 change: 1 addition & 0 deletions go-runtime/ftl/ftltest/testdata/go/outer/inner/inner.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package inner
13 changes: 13 additions & 0 deletions go-runtime/ftl/ftltest/testdata/go/outer/inner/inner_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package inner_test

import (
"testing"

"github.com/TBD54566975/ftl/go-runtime/ftl/reflection"
"github.com/alecthomas/assert/v2"
)

func TestInner(t *testing.T) {
// make sure that packages within a module are correctly identified as being part of the correct module
assert.Equal(t, "outer", reflection.Module())
}
1 change: 1 addition & 0 deletions go-runtime/ftl/ftltest/testdata/go/outer/outer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package outer
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package subscriber
package subscriber_test

import (
"ftl/pubsub"
Expand Down
3 changes: 3 additions & 0 deletions go-runtime/ftl/reflection/reflection.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ func Module() string {
debug.PrintStack()
panic("must be called from an FTL module")
}
if strings.HasSuffix(module, "_test") {
return module[:len(module)-len("_test")]
}
return module
}

Expand Down
2 changes: 1 addition & 1 deletion integration/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -484,5 +484,5 @@ func HttpCall(method string, path string, headers map[string][]string, body []by

// Run "go test" in the given module.
func ExecModuleTest(module string) Action {
return Chdir(module, Exec("go", "test", "-v", "."))
return Chdir(module, Exec("go", "test", "./..."))
}

0 comments on commit 037a172

Please sign in to comment.