Skip to content

Commit

Permalink
test: add unit test for catching cyclic verbs (#4733)
Browse files Browse the repository at this point in the history
closes #4633
  • Loading branch information
matt2e authored Mar 3, 2025
1 parent 7d0fbae commit 5d1a7b1
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
4 changes: 2 additions & 2 deletions go-runtime/compile/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,7 @@ func (b *mainDeploymentContextBuilder) visit(
}
err := b.visit(ctx, m, resolved, parents)
if err != nil {
return fmt.Errorf("failed to visit children of %s: %w", n, err)
return err //nolint:wrapcheck
}
return next()
default:
Expand Down Expand Up @@ -948,7 +948,7 @@ func (b *mainDeploymentContextBuilder) visit(
return next()
})
if err != nil {
return fmt.Errorf("failed to build main module context: %w", err)
return err //nolint:wrapcheck
}
return nil
}
Expand Down
38 changes: 38 additions & 0 deletions go-runtime/compile/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@ package compile
import (
"os"
"path/filepath"
stdslices "slices"
"testing"

"github.com/alecthomas/assert/v2"
"github.com/alecthomas/types/optional"

"github.com/block/ftl/common/schema"
"github.com/block/ftl/common/slices"
"github.com/block/ftl/common/strcase"
goschema "github.com/block/ftl/go-runtime/schema"
"github.com/block/ftl/go-runtime/schema/common"
"github.com/block/ftl/internal/watch"
)

Expand Down Expand Up @@ -105,3 +110,36 @@ go 1.23.0
_, _, err = updateGoModule(goModPath, "mymodule", optional.None[watch.ModifyFilesTransaction]())
assert.Contains(t, err.Error(), "module name mismatch: expected 'ftl/mymodule' but got 'ftl/wrongname'")
}

func TestCylicVerbs(t *testing.T) {
module, err := schema.ParseModuleString("", `
module cyclic {
verb a(Unit) Unit
+calls cyclic.b
verb b(Unit) Unit
+calls cyclic.c
verb c(Unit) Unit
+calls cyclic.a
}
`)
assert.NoError(t, err)
verbDecls := stdslices.Collect(slices.FilterVariants[*schema.Verb](module.Decls))
_, err = buildMainDeploymentContext(&schema.Schema{}, goschema.Result{
Module: module,
VerbResourceParamOrder: map[*schema.Verb][]common.VerbResourceParam{
verbDecls[0]: {},
verbDecls[1]: {},
verbDecls[2]: {},
},
NativeNames: goschema.NativeNames{
verbDecls[0]: "ftl/cyclic." + strcase.ToUpperCamel(module.Decls[0].GetName()),
verbDecls[1]: "ftl/cyclic." + strcase.ToUpperCamel(module.Decls[1].GetName()),
verbDecls[2]: "ftl/cyclic." + strcase.ToUpperCamel(module.Decls[2].GetName()),
},
},
"", "projectname", nil, nil)

assert.EqualError(t, err, "cyclic references are not allowed: cyclic.a refers to cyclic.b refers to cyclic.c refers to cyclic.a")
}
3 changes: 0 additions & 3 deletions go-runtime/schema/schema_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -513,9 +513,6 @@ func testParsedirectives(t *testing.T) {
}

func testErrorReporting(t *testing.T) {
}

func TestErrorReporting(t *testing.T) {
if testing.Short() {
t.SkipNow()
}
Expand Down

0 comments on commit 5d1a7b1

Please # to comment.