Skip to content

Commit

Permalink
init testdata module with subpackages
Browse files Browse the repository at this point in the history
subpackage test

add failing integration test

move tests up to parent package

test passes

lint

encoding test

put main init back

rebuild

add new gened file to gitignore

rm gened file from git

fix path

simplify

fix discover test

comment fix
  • Loading branch information
deniseli committed Jul 1, 2024
1 parent 3955cfa commit 4afcf6c
Show file tree
Hide file tree
Showing 12 changed files with 475 additions and 14 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ testdata/**/go.work
testdata/**/go.work.sum
**/testdata/**/_ftl
**/examples/**/_ftl
**/testdata/**/types.ftl.go
**/examples/**/types.ftl.go
buildengine/.gitignore
go.work*
junit*.xml
Expand Down
3 changes: 3 additions & 0 deletions backend/schema/encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ func EncodeComments(comments []string) string {

w := &strings.Builder{}
for _, c := range comments {
if c == "Code generated by FTL. DO NOT EDIT." {
continue
}
space := ""
// Empty lines should not have a trailing space.
if c != "" {
Expand Down
4 changes: 2 additions & 2 deletions buildengine/discover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestDiscoverModules(t *testing.T) {
DeployDir: "_ftl",
Schema: "schema.pb",
Errors: "errors.pb",
Watch: []string{"**/*.go", "go.mod", "go.sum", "../../../go-runtime/ftl/**/*.go"},
Watch: []string{"**/*.go", "go.mod", "go.sum", "../../../go-runtime/ftl/**/*.go", "../../../go-runtime/ftl/reflection/**/*.go"},
},
},
{
Expand Down Expand Up @@ -156,7 +156,7 @@ func TestDiscoverModules(t *testing.T) {
DeployDir: "_ftl",
Schema: "schema.pb",
Errors: "errors.pb",
Watch: []string{"**/*.go", "go.mod", "go.sum", "../../../go-runtime/ftl/**/*.go"},
Watch: []string{"**/*.go", "go.mod", "go.sum", "../../../go-runtime/ftl/**/*.go", "../../../go-runtime/ftl/reflection/**/*.go"},
},
},
}
Expand Down
17 changes: 17 additions & 0 deletions go-runtime/compile/build-template/types.ftl.go

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

49 changes: 37 additions & 12 deletions go-runtime/compile/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,13 @@ type goVerb struct {
}

type mainModuleContext struct {
GoVersion string
FTLVersion string
Name string
Verbs []goVerb
Replacements []*modfile.Replace
SumTypes []goSumType
GoVersion string
FTLVersion string
Name string
Verbs []goVerb
Replacements []*modfile.Replace
SumTypes []goSumType
LocalSumTypes []goSumType
}

type goSumType struct {
Expand Down Expand Up @@ -185,12 +186,13 @@ func Build(ctx context.Context, moduleDir string, sch *schema.Schema, filesTrans
goVerbs = append(goVerbs, goverb)
}
if err := internal.ScaffoldZip(buildTemplateFiles(), moduleDir, mainModuleContext{
GoVersion: goModVersion,
FTLVersion: ftlVersion,
Name: result.Module.Name,
Verbs: goVerbs,
Replacements: replacements,
SumTypes: getSumTypes(result.Module, sch, result.NativeNames),
GoVersion: goModVersion,
FTLVersion: ftlVersion,
Name: result.Module.Name,
Verbs: goVerbs,
Replacements: replacements,
SumTypes: getSumTypes(result.Module, sch, result.NativeNames),
LocalSumTypes: getLocalSumTypes(result.Module),
}, scaffolder.Exclude("^go.mod$"), scaffolder.Functions(funcs)); err != nil {
return err
}
Expand Down Expand Up @@ -553,6 +555,29 @@ func writeSchemaErrors(config moduleconfig.ModuleConfig, errors []*schema.Error)
return os.WriteFile(config.Abs().Errors, elBytes, 0600)
}

func getLocalSumTypes(module *schema.Module) []goSumType {
sumTypes := make(map[string]goSumType)
for _, d := range module.Decls {
if e, ok := d.(*schema.Enum); ok && !e.IsValueEnum() {
variants := make([]goSumTypeVariant, 0, len(e.Variants))
for _, v := range e.Variants {
variants = append(variants, goSumTypeVariant{ //nolint:forcetypeassert
Name: v.Name,
})
}
sumTypes[e.Name] = goSumType{
Discriminator: e.Name,
Variants: variants,
}
}
}
out := gomaps.Values(sumTypes)
slices.SortFunc(out, func(a, b goSumType) int {
return strings.Compare(a.Discriminator, b.Discriminator)
})
return out
}

func getSumTypes(module *schema.Module, sch *schema.Schema, nativeNames NativeNames) []goSumType {
sumTypes := make(map[string]goSumType)
for _, d := range module.Decls {
Expand Down
8 changes: 8 additions & 0 deletions go-runtime/ftl/ftl_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,11 @@ func TestSchemaGenerate(t *testing.T) {
in.FileContains("build/schema-generate/test.txt", "olleh"),
)
}

func TestTypeRegistryUnitTest(t *testing.T) {
in.Run(t, "",
in.CopyModule("typeregistry"),
in.Deploy("typeregistry"),
in.ExecModuleTest("typeregistry"),
)
}
2 changes: 2 additions & 0 deletions go-runtime/ftl/testdata/go/typeregistry/ftl.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module = "typeregistry"
language = "go"
63 changes: 63 additions & 0 deletions go-runtime/ftl/testdata/go/typeregistry/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
module ftl/typeregistry

go 1.22.2

toolchain go1.22.4

require (
github.com/TBD54566975/ftl v1.1.5
github.com/alecthomas/assert v1.0.0
)

require (
connectrpc.com/connect v1.16.1 // indirect
connectrpc.com/grpcreflect v1.2.0 // indirect
connectrpc.com/otelconnect v0.7.0 // indirect
github.com/BurntSushi/toml v1.4.0 // indirect
github.com/TBD54566975/scaffolder v1.0.0 // indirect
github.com/alecthomas/atomic v0.1.0-alpha2 // indirect
github.com/alecthomas/colour v0.1.0 // indirect
github.com/alecthomas/concurrency v0.0.2 // indirect
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/alessio/shellescape v1.4.2 // indirect
github.com/aws/aws-sdk-go-v2 v1.30.0 // indirect
github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.12 // indirect
github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.12 // indirect
github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.31.1 // indirect
github.com/aws/smithy-go v1.20.2 // indirect
github.com/benbjohnson/clock v1.3.5 // indirect
github.com/danieljoos/wincred v1.2.0 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/godbus/dbus/v5 v5.1.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/jackc/pgerrcode v0.0.0-20240316143900-6e2875d9b438 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
github.com/jackc/pgx/v5 v5.6.0 // indirect
github.com/jackc/puddle/v2 v2.2.1 // indirect
github.com/jpillora/backoff v1.0.0 // indirect
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/multiformats/go-base36 v0.2.0 // indirect
github.com/puzpuzpuz/xsync/v3 v3.2.0 // indirect
github.com/sergi/go-diff v1.3.1 // indirect
github.com/swaggest/jsonschema-go v0.3.72 // indirect
github.com/swaggest/refl v1.3.0 // indirect
github.com/zalando/go-keyring v0.2.5 // indirect
go.opentelemetry.io/otel v1.27.0 // indirect
go.opentelemetry.io/otel/metric v1.27.0 // indirect
go.opentelemetry.io/otel/trace v1.27.0 // indirect
golang.org/x/crypto v0.24.0 // indirect
golang.org/x/exp v0.0.0-20240604190554-fc45aab8b7f8 // indirect
golang.org/x/mod v0.18.0 // indirect
golang.org/x/net v0.26.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.21.0 // indirect
golang.org/x/text v0.16.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
)

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

0 comments on commit 4afcf6c

Please sign in to comment.