Skip to content

Commit

Permalink
test(buildengine): Convert buildengine tests into integration test (#…
Browse files Browse the repository at this point in the history
…2508)

See #1585

I left engine_test in place, as there was one test for graph
construction that could not be done nicely as an integration test.
  • Loading branch information
jvmakine authored Aug 27, 2024
1 parent 86ab6fa commit b29aca4
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 298 deletions.
56 changes: 56 additions & 0 deletions internal/buildengine/build_go_integration_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//go:build integration

package buildengine

import (
"os"
"testing"

"github.com/alecthomas/assert/v2"

in "github.com/TBD54566975/ftl/internal/integration"
)

func TestGoBuildClearsBuildDir(t *testing.T) {
file := "./another/.ftl/test-clear-build.tmp"
in.Run(t,
in.WithTestDataDir("testdata"),
in.CopyModule("another"),
in.WriteFile(file, []byte{1}),
in.FileExists(file),
in.Build("another"),
in.ExpectError(in.FileExists(file), "no such file"),
)
}

func TestExternalType(t *testing.T) {
in.Run(t,
in.WithTestDataDir("testdata"),
in.CopyModule("external"),
in.ExpectError(in.Build("external"),
`unsupported type "time.Month" for field "Month"`,
`unsupported external type "time.Month"; see FTL docs on using external types: tbd54566975.github.io/ftl/docs/reference/externaltypes/`,
`unsupported response type "ftl/external.ExternalResponse"`,
),
)
}

func TestGeneratedTypeRegistry(t *testing.T) {
expected, err := os.ReadFile("testdata/type_registry_main.go")
assert.NoError(t, err)

file := "other/.ftl/go/main/main.go"

in.Run(t,
in.WithTestDataDir("testdata"),
// Deploy dependency
in.CopyModule("another"),
in.Deploy("another"),
// Build the module under test
in.CopyModule("other"),
in.ExpectError(in.FileExists(file), "no such file"),
in.Build("other"),
// Validate the generated main.go
in.FileContent(file, string(expected)),
)
}
91 changes: 0 additions & 91 deletions internal/buildengine/build_go_test.go

This file was deleted.

167 changes: 0 additions & 167 deletions internal/buildengine/build_test.go

This file was deleted.

35 changes: 35 additions & 0 deletions internal/buildengine/engine_integration_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//go:build integration

package buildengine_test

import (
"testing"

in "github.com/TBD54566975/ftl/internal/integration"
)

func TestCycleDetection(t *testing.T) {
in.Run(t,
in.WithTestDataDir("testdata"),
in.CopyModule("depcycle1"),
in.CopyModule("depcycle2"),

in.ExpectError(
in.Build("depcycle1", "depcycle2"),
`detected a module dependency cycle that impacts these modules:`,
),
)
}

func TestInt64BuildError(t *testing.T) {
in.Run(t,
in.WithTestDataDir("testdata"),
in.CopyModule("integer"),

in.ExpectError(
in.Build("integer"),
`unsupported type "int64" for field "Input"`,
`unsupported type "int64" for field "Output"`,
),
)
}
36 changes: 1 addition & 35 deletions internal/buildengine/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ import (
"github.com/TBD54566975/ftl/internal/log"
)

func TestEngine(t *testing.T) {
if testing.Short() {
t.SkipNow()
}
func TestGraph(t *testing.T) {
ctx := log.ContextWithNewDefaultLogger(context.Background())
engine, err := buildengine.New(ctx, nil, t.TempDir(), []string{"testdata/alpha", "testdata/other", "testdata/another"})
assert.NoError(t, err)
Expand Down Expand Up @@ -58,34 +55,3 @@ func TestEngine(t *testing.T) {
err = engine.Build(ctx)
assert.NoError(t, err)
}

func TestCycleDetection(t *testing.T) {
if testing.Short() {
t.SkipNow()
}
ctx := log.ContextWithNewDefaultLogger(context.Background())
engine, err := buildengine.New(ctx, nil, t.TempDir(), []string{"testdata/depcycle1", "testdata/depcycle2"})
assert.NoError(t, err)

defer engine.Close()

err = engine.Build(ctx)
assert.Error(t, err)
assert.Contains(t, err.Error(), "detected a module dependency cycle that impacts these modules:")
}

func TestInt64BuildError(t *testing.T) {
if testing.Short() {
t.SkipNow()
}
ctx := log.ContextWithNewDefaultLogger(context.Background())
engine, err := buildengine.New(ctx, nil, t.TempDir(), []string{"testdata/integer"})
assert.NoError(t, err)

defer engine.Close()

err = engine.Build(ctx)
assert.Error(t, err)
assert.Contains(t, err.Error(), `unsupported type "int64" for field "Input"`)
assert.Contains(t, err.Error(), `unsupported type "int64" for field "Output"`)
}
Loading

0 comments on commit b29aca4

Please sign in to comment.