From d7075cd022972670d7d6f89514a29e37c0ac1116 Mon Sep 17 00:00:00 2001 From: Jon Johnson <113393155+jonathanj-square@users.noreply.github.com> Date: Tue, 4 Jun 2024 12:32:37 -0700 Subject: [PATCH] fixes #1606 migrating integration tests to their logical packages --- .../cronjobs/cronjobs_integration_test.go | 23 ++ .../cronjobs}/testdata/go/cron/cron.go | 0 .../cronjobs}/testdata/go/cron/ftl.toml | 0 .../cronjobs}/testdata/go/cron/go.mod | 2 +- .../cronjobs}/testdata/go/cron/go.sum | 0 .../controller/dal/fsm_integration_test.go | 117 +++++++ .../controller/dal}/testdata/go/fsm/fsm.go | 0 .../dal}/testdata/go/fsm/fsm_test.go | 0 .../controller/dal}/testdata/go/fsm/ftl.toml | 0 .../controller/dal}/testdata/go/fsm/go.mod | 2 +- .../controller/dal/testdata/go/fsm}/go.sum | 0 .../dal}/testdata/go/fsmretry/fsmretry.go | 0 .../dal}/testdata/go/fsmretry/ftl.toml | 0 .../dal}/testdata/go/fsmretry/go.mod | 2 +- .../dal/testdata/go/fsmretry}/go.sum | 0 .../ingress/testdata/go/httpingress/go.mod | 2 +- .../leases/lease_integration_test.go | 59 ++++ .../leases}/testdata/go/leases/ftl.toml | 0 .../leases}/testdata/go/leases/go.mod | 2 +- .../leases/testdata/go/leases}/go.sum | 0 .../leases}/testdata/go/leases/leases.go | 0 .../leases}/testdata/go/leases/leases_test.go | 0 .../sql/database_integration_test.go | 25 ++ .../sql}/testdata/go/database/database.go | 0 .../testdata/go/database/database_test.go | 0 .../testdata/go/database/ftl-project.toml | 0 .../sql}/testdata/go/database/ftl.toml | 0 .../sql}/testdata/go/database/go.mod | 2 +- .../sql/testdata/go/database}/go.sum | 0 buildengine/testdata/projects/alpha/go.sum | 4 + buildengine/testdata/projects/another/go.sum | 4 + buildengine/testdata/projects/other/go.sum | 4 + ftl-project.toml | 6 + .../compile/compile_integration_test.go | 35 +++ go-runtime/compile/testdata/failing/go.sum | 4 + .../compile}/testdata/go/echo/echo.go | 0 .../compile}/testdata/go/echo/ftl.toml | 0 .../compile}/testdata/go/echo/go.mod | 2 +- .../compile/testdata/go/echo}/go.sum | 0 .../testdata/go/notexportedverb/ftl.toml | 0 .../testdata/go/notexportedverb}/go.mod | 2 +- .../testdata/go/notexportedverb/go.sum | 0 .../go/notexportedverb/notexportedverb.go | 0 .../compile}/testdata/go/time/ftl.toml | 0 go-runtime/compile/testdata/go/time/go.mod | 5 + .../compile}/testdata/go/time/go.sum | 0 .../compile}/testdata/go/time/time.go | 0 .../testdata/go/undefinedverb/ftl.toml | 0 .../compile/testdata/go/undefinedverb}/go.mod | 2 +- .../compile/testdata/go/undefinedverb}/go.sum | 0 .../go/undefinedverb/undefinedverb.go | 0 go-runtime/compile/testdata/one/go.sum | 4 + go-runtime/compile/testdata/parent/go.sum | 4 + go-runtime/compile/testdata/pubsub/go.sum | 4 + go-runtime/compile/testdata/subscriber/go.sum | 4 + go-runtime/compile/testdata/two/go.sum | 4 + .../encoding/encoding_integration_test.go | 25 ++ .../encoding}/testdata/go/omitempty/ftl.toml | 0 .../encoding}/testdata/go/omitempty/go.mod | 2 +- .../encoding/testdata/go/omitempty}/go.sum | 0 .../testdata/go/omitempty/omitempty.go | 2 +- go-runtime/ftl/ftl_integration_test.go | 48 +++ .../ftl/ftltest/ftltest_integration_test.go | 20 ++ .../ftl/ftltest/testdata/go/time/ftl.toml | 5 + .../ftl/ftltest/testdata/go/time/go.mod | 5 + .../ftl/ftltest/testdata/go/time/go.sum | 0 .../ftl/ftltest/testdata/go/time/time.go | 18 ++ .../ftltest}/testdata/go/verbtypes/ftl.toml | 0 .../ftl/ftltest}/testdata/go/verbtypes/go.mod | 2 +- .../ftl/ftltest}/testdata/go/verbtypes/go.sum | 0 .../testdata/go/verbtypes/verbtypes.go | 0 .../testdata/go/verbtypes/verbtypes_test.go | 0 .../go/wrapped/ftl-project-test-1.toml | 0 .../go/wrapped/ftl-project-test-2.toml | 0 .../testdata/go/wrapped/ftl-project.toml | 0 .../ftl/ftltest}/testdata/go/wrapped/ftl.toml | 0 .../ftl/ftltest}/testdata/go/wrapped/go.mod | 2 +- .../ftl/ftltest}/testdata/go/wrapped/go.sum | 0 .../ftltest}/testdata/go/wrapped/wrapped.go | 0 .../testdata/go/wrapped/wrapped_test.go | 0 .../reflection/reflection_integration_test.go | 16 + .../testdata/go/runtimereflection/ftl.toml | 0 .../testdata/go/runtimereflection/go.mod | 2 +- .../testdata/go/runtimereflection}/go.sum | 0 .../go/runtimereflection/runtimereflection.go | 0 .../runtimereflection_test.go | 0 go-runtime/ftl/testdata/go/echo/echo.go | 34 ++ go-runtime/ftl/testdata/go/echo/ftl.toml | 2 + go-runtime/ftl/testdata/go/echo/go.mod | 43 +++ go-runtime/ftl/testdata/go/echo/go.sum | 136 ++++++++ go-runtime/ftl/testdata/go/time/ftl.toml | 5 + go-runtime/ftl/testdata/go/time/go.mod | 5 + go-runtime/ftl/testdata/go/time/go.sum | 0 go-runtime/ftl/testdata/go/time/time.go | 18 ++ .../ftl}/testdata/schema-generate/go.mod | 0 .../ftl}/testdata/schema-generate/template.js | 0 .../ftl}/testdata/schema-generate/test.txt | 0 integration/integration_test.go | 296 ------------------ integration/testdata/go/time/go.mod | 5 - 99 files changed, 700 insertions(+), 315 deletions(-) rename {integration => backend/controller/cronjobs}/testdata/go/cron/cron.go (100%) rename {integration => backend/controller/cronjobs}/testdata/go/cron/ftl.toml (100%) rename {integration => backend/controller/cronjobs}/testdata/go/cron/go.mod (96%) rename {integration => backend/controller/cronjobs}/testdata/go/cron/go.sum (100%) create mode 100644 backend/controller/dal/fsm_integration_test.go rename {integration => backend/controller/dal}/testdata/go/fsm/fsm.go (100%) rename {integration => backend/controller/dal}/testdata/go/fsm/fsm_test.go (100%) rename {integration => backend/controller/dal}/testdata/go/fsm/ftl.toml (100%) rename {integration => backend/controller/dal}/testdata/go/fsm/go.mod (97%) rename {integration/testdata/go/database => backend/controller/dal/testdata/go/fsm}/go.sum (100%) rename {integration => backend/controller/dal}/testdata/go/fsmretry/fsmretry.go (100%) rename {integration => backend/controller/dal}/testdata/go/fsmretry/ftl.toml (100%) rename {integration => backend/controller/dal}/testdata/go/fsmretry/go.mod (96%) rename {integration/testdata/go/echo => backend/controller/dal/testdata/go/fsmretry}/go.sum (100%) create mode 100644 backend/controller/leases/lease_integration_test.go rename {integration => backend/controller/leases}/testdata/go/leases/ftl.toml (100%) rename {integration => backend/controller/leases}/testdata/go/leases/go.mod (97%) rename {integration/testdata/go/fsm => backend/controller/leases/testdata/go/leases}/go.sum (100%) rename {integration => backend/controller/leases}/testdata/go/leases/leases.go (100%) rename {integration => backend/controller/leases}/testdata/go/leases/leases_test.go (100%) create mode 100644 backend/controller/sql/database_integration_test.go rename {integration => backend/controller/sql}/testdata/go/database/database.go (100%) rename {integration => backend/controller/sql}/testdata/go/database/database_test.go (100%) rename {integration => backend/controller/sql}/testdata/go/database/ftl-project.toml (100%) rename {integration => backend/controller/sql}/testdata/go/database/ftl.toml (100%) rename {integration => backend/controller/sql}/testdata/go/database/go.mod (97%) rename {integration/testdata/go/leases => backend/controller/sql/testdata/go/database}/go.sum (100%) create mode 100644 go-runtime/compile/compile_integration_test.go rename {integration => go-runtime/compile}/testdata/go/echo/echo.go (100%) rename {integration => go-runtime/compile}/testdata/go/echo/ftl.toml (100%) rename {integration => go-runtime/compile}/testdata/go/echo/go.mod (96%) rename {integration/testdata/go/fsmretry => go-runtime/compile/testdata/go/echo}/go.sum (100%) rename {integration => go-runtime/compile}/testdata/go/notexportedverb/ftl.toml (100%) rename {integration/testdata/go/undefinedverb => go-runtime/compile/testdata/go/notexportedverb}/go.mod (96%) rename {integration => go-runtime/compile}/testdata/go/notexportedverb/go.sum (100%) rename {integration => go-runtime/compile}/testdata/go/notexportedverb/notexportedverb.go (100%) rename {integration => go-runtime/compile}/testdata/go/time/ftl.toml (100%) create mode 100644 go-runtime/compile/testdata/go/time/go.mod rename {integration => go-runtime/compile}/testdata/go/time/go.sum (100%) rename {integration => go-runtime/compile}/testdata/go/time/time.go (100%) rename {integration => go-runtime/compile}/testdata/go/undefinedverb/ftl.toml (100%) rename {integration/testdata/go/notexportedverb => go-runtime/compile/testdata/go/undefinedverb}/go.mod (96%) rename {integration/testdata/go/omitempty => go-runtime/compile/testdata/go/undefinedverb}/go.sum (100%) rename {integration => go-runtime/compile}/testdata/go/undefinedverb/undefinedverb.go (100%) create mode 100644 go-runtime/encoding/encoding_integration_test.go rename {integration => go-runtime/encoding}/testdata/go/omitempty/ftl.toml (100%) rename {integration => go-runtime/encoding}/testdata/go/omitempty/go.mod (96%) rename {integration/testdata/go/runtimereflection => go-runtime/encoding/testdata/go/omitempty}/go.sum (100%) rename {integration => go-runtime/encoding}/testdata/go/omitempty/omitempty.go (93%) create mode 100644 go-runtime/ftl/ftl_integration_test.go create mode 100644 go-runtime/ftl/ftltest/ftltest_integration_test.go create mode 100644 go-runtime/ftl/ftltest/testdata/go/time/ftl.toml create mode 100644 go-runtime/ftl/ftltest/testdata/go/time/go.mod create mode 100644 go-runtime/ftl/ftltest/testdata/go/time/go.sum create mode 100644 go-runtime/ftl/ftltest/testdata/go/time/time.go rename {integration => go-runtime/ftl/ftltest}/testdata/go/verbtypes/ftl.toml (100%) rename {integration => go-runtime/ftl/ftltest}/testdata/go/verbtypes/go.mod (97%) rename {integration => go-runtime/ftl/ftltest}/testdata/go/verbtypes/go.sum (100%) rename {integration => go-runtime/ftl/ftltest}/testdata/go/verbtypes/verbtypes.go (100%) rename {integration => go-runtime/ftl/ftltest}/testdata/go/verbtypes/verbtypes_test.go (100%) rename {integration => go-runtime/ftl/ftltest}/testdata/go/wrapped/ftl-project-test-1.toml (100%) rename {integration => go-runtime/ftl/ftltest}/testdata/go/wrapped/ftl-project-test-2.toml (100%) rename {integration => go-runtime/ftl/ftltest}/testdata/go/wrapped/ftl-project.toml (100%) rename {integration => go-runtime/ftl/ftltest}/testdata/go/wrapped/ftl.toml (100%) rename {integration => go-runtime/ftl/ftltest}/testdata/go/wrapped/go.mod (97%) rename {integration => go-runtime/ftl/ftltest}/testdata/go/wrapped/go.sum (100%) rename {integration => go-runtime/ftl/ftltest}/testdata/go/wrapped/wrapped.go (100%) rename {integration => go-runtime/ftl/ftltest}/testdata/go/wrapped/wrapped_test.go (100%) create mode 100644 go-runtime/ftl/reflection/reflection_integration_test.go rename {integration => go-runtime/ftl/reflection}/testdata/go/runtimereflection/ftl.toml (100%) rename {integration => go-runtime/ftl/reflection}/testdata/go/runtimereflection/go.mod (96%) rename {integration/testdata/go/undefinedverb => go-runtime/ftl/reflection/testdata/go/runtimereflection}/go.sum (100%) rename {integration => go-runtime/ftl/reflection}/testdata/go/runtimereflection/runtimereflection.go (100%) rename {integration => go-runtime/ftl/reflection}/testdata/go/runtimereflection/runtimereflection_test.go (100%) create mode 100644 go-runtime/ftl/testdata/go/echo/echo.go create mode 100644 go-runtime/ftl/testdata/go/echo/ftl.toml create mode 100644 go-runtime/ftl/testdata/go/echo/go.mod create mode 100644 go-runtime/ftl/testdata/go/echo/go.sum create mode 100644 go-runtime/ftl/testdata/go/time/ftl.toml create mode 100644 go-runtime/ftl/testdata/go/time/go.mod create mode 100644 go-runtime/ftl/testdata/go/time/go.sum create mode 100644 go-runtime/ftl/testdata/go/time/time.go rename {integration => go-runtime/ftl}/testdata/schema-generate/go.mod (100%) rename {integration => go-runtime/ftl}/testdata/schema-generate/template.js (100%) rename {integration => go-runtime/ftl}/testdata/schema-generate/test.txt (100%) delete mode 100644 integration/integration_test.go delete mode 100644 integration/testdata/go/time/go.mod diff --git a/backend/controller/cronjobs/cronjobs_integration_test.go b/backend/controller/cronjobs/cronjobs_integration_test.go index 54e0a92d3a..9e4d74507a 100644 --- a/backend/controller/cronjobs/cronjobs_integration_test.go +++ b/backend/controller/cronjobs/cronjobs_integration_test.go @@ -4,11 +4,14 @@ package cronjobs import ( "context" + "os" + "path/filepath" "testing" "time" db "github.com/TBD54566975/ftl/backend/controller/dal" "github.com/TBD54566975/ftl/backend/controller/sql/sqltest" + in "github.com/TBD54566975/ftl/integration" "github.com/TBD54566975/ftl/internal/log" "github.com/alecthomas/assert/v2" "github.com/benbjohnson/clock" @@ -35,3 +38,23 @@ func TestServiceWithRealDal(t *testing.T) { testServiceWithDal(ctx, t, dal, clk) } + +func TestCron(t *testing.T) { + dir := t.TempDir() + // Due to some MacOS magic, /tmp differs between this test code and the + // executing module, so we need to pass the file path as an environment + // variable. + tmpFile := filepath.Join(dir, "cron.txt") + t.Setenv("DEST_FILE", tmpFile) + + t.Cleanup(func() { _ = os.Remove(tmpFile) }) + + in.Run(t, "", + in.CopyModule("cron"), + in.Deploy("cron"), + func(t testing.TB, ic in.TestContext) { + _, err := os.Stat(tmpFile) + assert.NoError(t, err) + }, + ) +} diff --git a/integration/testdata/go/cron/cron.go b/backend/controller/cronjobs/testdata/go/cron/cron.go similarity index 100% rename from integration/testdata/go/cron/cron.go rename to backend/controller/cronjobs/testdata/go/cron/cron.go diff --git a/integration/testdata/go/cron/ftl.toml b/backend/controller/cronjobs/testdata/go/cron/ftl.toml similarity index 100% rename from integration/testdata/go/cron/ftl.toml rename to backend/controller/cronjobs/testdata/go/cron/ftl.toml diff --git a/integration/testdata/go/cron/go.mod b/backend/controller/cronjobs/testdata/go/cron/go.mod similarity index 96% rename from integration/testdata/go/cron/go.mod rename to backend/controller/cronjobs/testdata/go/cron/go.mod index 42d911b661..266378ba3f 100644 --- a/integration/testdata/go/cron/go.mod +++ b/backend/controller/cronjobs/testdata/go/cron/go.mod @@ -40,4 +40,4 @@ require ( google.golang.org/protobuf v1.34.1 // indirect ) -replace github.com/TBD54566975/ftl => ../../../.. +replace github.com/TBD54566975/ftl => ./../../../../../.. diff --git a/integration/testdata/go/cron/go.sum b/backend/controller/cronjobs/testdata/go/cron/go.sum similarity index 100% rename from integration/testdata/go/cron/go.sum rename to backend/controller/cronjobs/testdata/go/cron/go.sum diff --git a/backend/controller/dal/fsm_integration_test.go b/backend/controller/dal/fsm_integration_test.go new file mode 100644 index 0000000000..5874fdc999 --- /dev/null +++ b/backend/controller/dal/fsm_integration_test.go @@ -0,0 +1,117 @@ +//go:build integration + +package dal_test + +import ( + "fmt" + "path/filepath" + "testing" + "time" + + in "github.com/TBD54566975/ftl/integration" + "github.com/alecthomas/assert/v2" +) + +func TestFSM(t *testing.T) { + logFilePath := filepath.Join(t.TempDir(), "fsm.log") + t.Setenv("FSM_LOG_FILE", logFilePath) + fsmInState := func(instance, status, state string) in.Action { + return in.QueryRow("ftl", fmt.Sprintf(` + SELECT status, current_state + FROM fsm_instances + WHERE fsm = 'fsm.fsm' AND key = '%s' + `, instance), status, state) + } + in.Run(t, "", + in.CopyModule("fsm"), + in.Deploy("fsm"), + + in.Call("fsm", "sendOne", in.Obj{"instance": "1"}, nil), + in.Call("fsm", "sendOne", in.Obj{"instance": "2"}, nil), + in.FileContains(logFilePath, "start 1"), + in.FileContains(logFilePath, "start 2"), + fsmInState("1", "running", "fsm.start"), + fsmInState("2", "running", "fsm.start"), + + in.Call("fsm", "sendOne", in.Obj{"instance": "1"}, nil), + in.FileContains(logFilePath, "middle 1"), + fsmInState("1", "running", "fsm.middle"), + + in.Call("fsm", "sendOne", in.Obj{"instance": "1"}, nil), + in.FileContains(logFilePath, "end 1"), + fsmInState("1", "completed", "fsm.end"), + + in.Fail(in.Call("fsm", "sendOne", in.Obj{"instance": "1"}, nil), + "FSM instance 1 is already in state fsm.end"), + + // Invalid state transition + in.Fail(in.Call("fsm", "sendTwo", in.Obj{"instance": "2"}, nil), + "invalid state transition"), + + in.Call("fsm", "sendOne", in.Obj{"instance": "2"}, nil), + in.FileContains(logFilePath, "middle 2"), + fsmInState("2", "running", "fsm.middle"), + + // Invalid state transition + in.Fail(in.Call("fsm", "sendTwo", in.Obj{"instance": "2"}, nil), + "invalid state transition"), + ) +} + +func TestFSMRetry(t *testing.T) { + checkRetries := func(origin, verb string, delays []time.Duration) in.Action { + return func(t testing.TB, ic in.TestContext) { + results := []any{} + for i := 0; i < len(delays); i++ { + values := in.GetRow(t, ic, "ftl", fmt.Sprintf("SELECT scheduled_at FROM async_calls WHERE origin = '%s' AND verb = '%s' AND state = 'error' ORDER BY created_at LIMIT 1 OFFSET %d", origin, verb, i), 1) + results = append(results, values[0]) + } + times := []time.Time{} + for i, r := range results { + ts, ok := r.(time.Time) + assert.True(t, ok, "unexpected time value: %v", r) + times = append(times, ts) + if i > 0 { + delay := times[i].Sub(times[i-1]) + targetDelay := delays[i-1] + assert.True(t, delay >= targetDelay && delay < time.Second+targetDelay, "unexpected time diff for %s retry %d: %v (expected %v - %v)", origin, i, delay, targetDelay, time.Second+targetDelay) + } + } + } + } + + in.Run(t, "", + in.CopyModule("fsmretry"), + in.Build("fsmretry"), + in.Deploy("fsmretry"), + // start 2 FSM instances + in.Call("fsmretry", "start", in.Obj{"id": "1"}, func(t testing.TB, response in.Obj) {}), + in.Call("fsmretry", "start", in.Obj{"id": "2"}, func(t testing.TB, response in.Obj) {}), + + in.Sleep(2*time.Second), + + // transition the FSM, should fail each time. + in.Call("fsmretry", "startTransitionToTwo", in.Obj{"id": "1"}, func(t testing.TB, response in.Obj) {}), + in.Call("fsmretry", "startTransitionToThree", in.Obj{"id": "2"}, func(t testing.TB, response in.Obj) {}), + + in.Sleep(8*time.Second), //6s is longest run of retries + + // both FSMs instances should have failed + in.QueryRow("ftl", "SELECT COUNT(*) FROM fsm_instances WHERE status = 'failed'", int64(2)), + + in.QueryRow("ftl", fmt.Sprintf("SELECT COUNT(*) FROM async_calls WHERE origin = '%s' AND verb = '%s'", "fsm:fsmretry.fsm:1", "fsmretry.state2"), int64(4)), + checkRetries("fsm:fsmretry.fsm:1", "fsmretry.state2", []time.Duration{time.Second, time.Second, time.Second}), + in.QueryRow("ftl", fmt.Sprintf("SELECT COUNT(*) FROM async_calls WHERE origin = '%s' AND verb = '%s'", "fsm:fsmretry.fsm:2", "fsmretry.state3"), int64(4)), + checkRetries("fsm:fsmretry.fsm:2", "fsmretry.state3", []time.Duration{time.Second, 2 * time.Second, 3 * time.Second}), + ) +} + +func TestFSMGoTests(t *testing.T) { + logFilePath := filepath.Join(t.TempDir(), "fsm.log") + t.Setenv("FSM_LOG_FILE", logFilePath) + in.Run(t, "", + in.CopyModule("fsm"), + in.Build("fsm"), + in.ExecModuleTest("fsm"), + ) +} diff --git a/integration/testdata/go/fsm/fsm.go b/backend/controller/dal/testdata/go/fsm/fsm.go similarity index 100% rename from integration/testdata/go/fsm/fsm.go rename to backend/controller/dal/testdata/go/fsm/fsm.go diff --git a/integration/testdata/go/fsm/fsm_test.go b/backend/controller/dal/testdata/go/fsm/fsm_test.go similarity index 100% rename from integration/testdata/go/fsm/fsm_test.go rename to backend/controller/dal/testdata/go/fsm/fsm_test.go diff --git a/integration/testdata/go/fsm/ftl.toml b/backend/controller/dal/testdata/go/fsm/ftl.toml similarity index 100% rename from integration/testdata/go/fsm/ftl.toml rename to backend/controller/dal/testdata/go/fsm/ftl.toml diff --git a/integration/testdata/go/fsm/go.mod b/backend/controller/dal/testdata/go/fsm/go.mod similarity index 97% rename from integration/testdata/go/fsm/go.mod rename to backend/controller/dal/testdata/go/fsm/go.mod index 229593248a..a8f0d9ce26 100644 --- a/integration/testdata/go/fsm/go.mod +++ b/backend/controller/dal/testdata/go/fsm/go.mod @@ -60,4 +60,4 @@ require ( google.golang.org/protobuf v1.34.1 // indirect ) -replace github.com/TBD54566975/ftl => ../../../.. +replace github.com/TBD54566975/ftl => ./../../../../../.. diff --git a/integration/testdata/go/database/go.sum b/backend/controller/dal/testdata/go/fsm/go.sum similarity index 100% rename from integration/testdata/go/database/go.sum rename to backend/controller/dal/testdata/go/fsm/go.sum diff --git a/integration/testdata/go/fsmretry/fsmretry.go b/backend/controller/dal/testdata/go/fsmretry/fsmretry.go similarity index 100% rename from integration/testdata/go/fsmretry/fsmretry.go rename to backend/controller/dal/testdata/go/fsmretry/fsmretry.go diff --git a/integration/testdata/go/fsmretry/ftl.toml b/backend/controller/dal/testdata/go/fsmretry/ftl.toml similarity index 100% rename from integration/testdata/go/fsmretry/ftl.toml rename to backend/controller/dal/testdata/go/fsmretry/ftl.toml diff --git a/integration/testdata/go/fsmretry/go.mod b/backend/controller/dal/testdata/go/fsmretry/go.mod similarity index 96% rename from integration/testdata/go/fsmretry/go.mod rename to backend/controller/dal/testdata/go/fsmretry/go.mod index 48e5e3b8e6..69d56bd192 100644 --- a/integration/testdata/go/fsmretry/go.mod +++ b/backend/controller/dal/testdata/go/fsmretry/go.mod @@ -42,4 +42,4 @@ require ( google.golang.org/protobuf v1.34.1 // indirect ) -replace github.com/TBD54566975/ftl => ../../../.. +replace github.com/TBD54566975/ftl => ./../../../../../.. diff --git a/integration/testdata/go/echo/go.sum b/backend/controller/dal/testdata/go/fsmretry/go.sum similarity index 100% rename from integration/testdata/go/echo/go.sum rename to backend/controller/dal/testdata/go/fsmretry/go.sum diff --git a/backend/controller/ingress/testdata/go/httpingress/go.mod b/backend/controller/ingress/testdata/go/httpingress/go.mod index d83d4f1e55..28f7cfb895 100644 --- a/backend/controller/ingress/testdata/go/httpingress/go.mod +++ b/backend/controller/ingress/testdata/go/httpingress/go.mod @@ -40,4 +40,4 @@ require ( google.golang.org/protobuf v1.34.1 // indirect ) -replace github.com/TBD54566975/ftl => ../../../.. +replace github.com/TBD54566975/ftl => ./../../../../../.. diff --git a/backend/controller/leases/lease_integration_test.go b/backend/controller/leases/lease_integration_test.go new file mode 100644 index 0000000000..f06fbbe87f --- /dev/null +++ b/backend/controller/leases/lease_integration_test.go @@ -0,0 +1,59 @@ +//go:build integration + +package leases_test + +import ( + "fmt" + "strings" + "testing" + "time" + + "connectrpc.com/connect" + "github.com/alecthomas/assert/v2" + "golang.org/x/sync/errgroup" + + ftlv1 "github.com/TBD54566975/ftl/backend/protos/xyz/block/ftl/v1" + schemapb "github.com/TBD54566975/ftl/backend/protos/xyz/block/ftl/v1/schema" + in "github.com/TBD54566975/ftl/integration" +) + +func TestLease(t *testing.T) { + in.Run(t, "", + in.CopyModule("leases"), + in.Build("leases"), + // checks if leases work in a unit test environment + in.ExecModuleTest("leases"), + in.Deploy("leases"), + // checks if it leases work with a real controller + func(t testing.TB, ic in.TestContext) { + // Start a lease. + wg := errgroup.Group{} + wg.Go(func() error { + in.Infof("Acquiring lease") + resp, err := ic.Verbs.Call(ic, connect.NewRequest(&ftlv1.CallRequest{ + Verb: &schemapb.Ref{Module: "leases", Name: "acquire"}, + Body: []byte("{}"), + })) + if respErr := resp.Msg.GetError(); respErr != nil { + return fmt.Errorf("received error on first call: %v", respErr) + } + return err + }) + + time.Sleep(time.Second) + + in.Infof("Trying to acquire lease again") + // Trying to obtain the lease again should fail. + resp, err := ic.Verbs.Call(ic, connect.NewRequest(&ftlv1.CallRequest{ + Verb: &schemapb.Ref{Module: "leases", Name: "acquire"}, + Body: []byte("{}"), + })) + assert.NoError(t, err) + if resp.Msg.GetError() == nil || !strings.Contains(resp.Msg.GetError().Message, "could not acquire lease") { + t.Fatalf("expected error but got: %#v", resp.Msg.GetError()) + } + err = wg.Wait() + assert.NoError(t, err) + }, + ) +} diff --git a/integration/testdata/go/leases/ftl.toml b/backend/controller/leases/testdata/go/leases/ftl.toml similarity index 100% rename from integration/testdata/go/leases/ftl.toml rename to backend/controller/leases/testdata/go/leases/ftl.toml diff --git a/integration/testdata/go/leases/go.mod b/backend/controller/leases/testdata/go/leases/go.mod similarity index 97% rename from integration/testdata/go/leases/go.mod rename to backend/controller/leases/testdata/go/leases/go.mod index 78a2a2d2d9..e1ecb5e86f 100644 --- a/integration/testdata/go/leases/go.mod +++ b/backend/controller/leases/testdata/go/leases/go.mod @@ -2,7 +2,7 @@ module ftl/leases go 1.22.2 -replace github.com/TBD54566975/ftl => ../../../.. +replace github.com/TBD54566975/ftl => ./../../../../../.. require ( github.com/TBD54566975/ftl v0.0.0-00010101000000-000000000000 diff --git a/integration/testdata/go/fsm/go.sum b/backend/controller/leases/testdata/go/leases/go.sum similarity index 100% rename from integration/testdata/go/fsm/go.sum rename to backend/controller/leases/testdata/go/leases/go.sum diff --git a/integration/testdata/go/leases/leases.go b/backend/controller/leases/testdata/go/leases/leases.go similarity index 100% rename from integration/testdata/go/leases/leases.go rename to backend/controller/leases/testdata/go/leases/leases.go diff --git a/integration/testdata/go/leases/leases_test.go b/backend/controller/leases/testdata/go/leases/leases_test.go similarity index 100% rename from integration/testdata/go/leases/leases_test.go rename to backend/controller/leases/testdata/go/leases/leases_test.go diff --git a/backend/controller/sql/database_integration_test.go b/backend/controller/sql/database_integration_test.go new file mode 100644 index 0000000000..ebbd8f8b02 --- /dev/null +++ b/backend/controller/sql/database_integration_test.go @@ -0,0 +1,25 @@ +//go:build integration + +package sql_test + +import ( + "testing" + + in "github.com/TBD54566975/ftl/integration" +) + +func TestDatabase(t *testing.T) { + in.Run(t, "database/ftl-project.toml", + // deploy real module against "testdb" + in.CopyModule("database"), + in.CreateDBAction("database", "testdb", false), + in.Deploy("database"), + in.Call("database", "insert", in.Obj{"data": "hello"}, nil), + in.QueryRow("testdb", "SELECT data FROM requests", "hello"), + + // run tests which should only affect "testdb_test" + in.CreateDBAction("database", "testdb", true), + in.ExecModuleTest("database"), + in.QueryRow("testdb", "SELECT data FROM requests", "hello"), + ) +} diff --git a/integration/testdata/go/database/database.go b/backend/controller/sql/testdata/go/database/database.go similarity index 100% rename from integration/testdata/go/database/database.go rename to backend/controller/sql/testdata/go/database/database.go diff --git a/integration/testdata/go/database/database_test.go b/backend/controller/sql/testdata/go/database/database_test.go similarity index 100% rename from integration/testdata/go/database/database_test.go rename to backend/controller/sql/testdata/go/database/database_test.go diff --git a/integration/testdata/go/database/ftl-project.toml b/backend/controller/sql/testdata/go/database/ftl-project.toml similarity index 100% rename from integration/testdata/go/database/ftl-project.toml rename to backend/controller/sql/testdata/go/database/ftl-project.toml diff --git a/integration/testdata/go/database/ftl.toml b/backend/controller/sql/testdata/go/database/ftl.toml similarity index 100% rename from integration/testdata/go/database/ftl.toml rename to backend/controller/sql/testdata/go/database/ftl.toml diff --git a/integration/testdata/go/database/go.mod b/backend/controller/sql/testdata/go/database/go.mod similarity index 97% rename from integration/testdata/go/database/go.mod rename to backend/controller/sql/testdata/go/database/go.mod index 2186267f3a..94b429f99f 100644 --- a/integration/testdata/go/database/go.mod +++ b/backend/controller/sql/testdata/go/database/go.mod @@ -58,4 +58,4 @@ require ( google.golang.org/protobuf v1.34.1 // indirect ) -replace github.com/TBD54566975/ftl => ../../../.. +replace github.com/TBD54566975/ftl => ./../../../../../.. diff --git a/integration/testdata/go/leases/go.sum b/backend/controller/sql/testdata/go/database/go.sum similarity index 100% rename from integration/testdata/go/leases/go.sum rename to backend/controller/sql/testdata/go/database/go.sum diff --git a/buildengine/testdata/projects/alpha/go.sum b/buildengine/testdata/projects/alpha/go.sum index d823b5af4a..d4b84ece19 100644 --- a/buildengine/testdata/projects/alpha/go.sum +++ b/buildengine/testdata/projects/alpha/go.sum @@ -4,6 +4,8 @@ connectrpc.com/grpcreflect v1.2.0 h1:Q6og1S7HinmtbEuBvARLNwYmTbhEGRpHDhqrPNlmK+U connectrpc.com/grpcreflect v1.2.0/go.mod h1:nwSOKmE8nU5u/CidgHtPYk1PFI3U9ignz7iDMxOYkSY= connectrpc.com/otelconnect v0.7.0 h1:ZH55ZZtcJOTKWWLy3qmL4Pam4RzRWBJFOqTPyAqCXkY= connectrpc.com/otelconnect v0.7.0/go.mod h1:Bt2ivBymHZHqxvo4HkJ0EwHuUzQN6k2l0oH+mp/8nwc= +github.com/TBD54566975/scaffolder v1.0.0 h1:QUFSy2wVzumLDg7IHcKC6AP+IYyqWe9Wxiu72nZn5qU= +github.com/TBD54566975/scaffolder v1.0.0/go.mod h1:auVpczIbOAdIhYDVSruIw41DanxOKB9bSvjf6MEl7Fs= github.com/alecthomas/assert/v2 v2.10.0 h1:jjRCHsj6hBJhkmhznrCzoNpbA3zqy0fYiUcYZP/GkPY= github.com/alecthomas/assert/v2 v2.10.0/go.mod h1:Bze95FyfUr7x34QZrjL+XP+0qgp/zg8yS+TtBj1WA3k= github.com/alecthomas/concurrency v0.0.2 h1:Q3kGPtLbleMbH9lHX5OBFvJygfyFw29bXZKBg+IEVuo= @@ -62,6 +64,8 @@ github.com/multiformats/go-base36 v0.2.0 h1:lFsAbNOGeKtuKozrtBsAkSVhv1p9D0/qedU9 github.com/multiformats/go-base36 v0.2.0/go.mod h1:qvnKE++v+2MWCfePClUEjE78Z7P2a1UV0xHgWc0hkp4= github.com/ncruces/go-strftime v0.1.9 h1:bY0MQC28UADQmHmaF5dgpLmImcShSi2kHU9XLdhx/f4= github.com/ncruces/go-strftime v0.1.9/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls= +github.com/otiai10/copy v1.14.0 h1:dCI/t1iTdYGtkvCuBG2BgR6KZa83PTclw4U5n2wAllU= +github.com/otiai10/copy v1.14.0/go.mod h1:ECfuL02W+/FkTWZWgQqXPWZgW9oeKCSQ5qVfSc4qc4w= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE= diff --git a/buildengine/testdata/projects/another/go.sum b/buildengine/testdata/projects/another/go.sum index d823b5af4a..d4b84ece19 100644 --- a/buildengine/testdata/projects/another/go.sum +++ b/buildengine/testdata/projects/another/go.sum @@ -4,6 +4,8 @@ connectrpc.com/grpcreflect v1.2.0 h1:Q6og1S7HinmtbEuBvARLNwYmTbhEGRpHDhqrPNlmK+U connectrpc.com/grpcreflect v1.2.0/go.mod h1:nwSOKmE8nU5u/CidgHtPYk1PFI3U9ignz7iDMxOYkSY= connectrpc.com/otelconnect v0.7.0 h1:ZH55ZZtcJOTKWWLy3qmL4Pam4RzRWBJFOqTPyAqCXkY= connectrpc.com/otelconnect v0.7.0/go.mod h1:Bt2ivBymHZHqxvo4HkJ0EwHuUzQN6k2l0oH+mp/8nwc= +github.com/TBD54566975/scaffolder v1.0.0 h1:QUFSy2wVzumLDg7IHcKC6AP+IYyqWe9Wxiu72nZn5qU= +github.com/TBD54566975/scaffolder v1.0.0/go.mod h1:auVpczIbOAdIhYDVSruIw41DanxOKB9bSvjf6MEl7Fs= github.com/alecthomas/assert/v2 v2.10.0 h1:jjRCHsj6hBJhkmhznrCzoNpbA3zqy0fYiUcYZP/GkPY= github.com/alecthomas/assert/v2 v2.10.0/go.mod h1:Bze95FyfUr7x34QZrjL+XP+0qgp/zg8yS+TtBj1WA3k= github.com/alecthomas/concurrency v0.0.2 h1:Q3kGPtLbleMbH9lHX5OBFvJygfyFw29bXZKBg+IEVuo= @@ -62,6 +64,8 @@ github.com/multiformats/go-base36 v0.2.0 h1:lFsAbNOGeKtuKozrtBsAkSVhv1p9D0/qedU9 github.com/multiformats/go-base36 v0.2.0/go.mod h1:qvnKE++v+2MWCfePClUEjE78Z7P2a1UV0xHgWc0hkp4= github.com/ncruces/go-strftime v0.1.9 h1:bY0MQC28UADQmHmaF5dgpLmImcShSi2kHU9XLdhx/f4= github.com/ncruces/go-strftime v0.1.9/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls= +github.com/otiai10/copy v1.14.0 h1:dCI/t1iTdYGtkvCuBG2BgR6KZa83PTclw4U5n2wAllU= +github.com/otiai10/copy v1.14.0/go.mod h1:ECfuL02W+/FkTWZWgQqXPWZgW9oeKCSQ5qVfSc4qc4w= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE= diff --git a/buildengine/testdata/projects/other/go.sum b/buildengine/testdata/projects/other/go.sum index d823b5af4a..d4b84ece19 100644 --- a/buildengine/testdata/projects/other/go.sum +++ b/buildengine/testdata/projects/other/go.sum @@ -4,6 +4,8 @@ connectrpc.com/grpcreflect v1.2.0 h1:Q6og1S7HinmtbEuBvARLNwYmTbhEGRpHDhqrPNlmK+U connectrpc.com/grpcreflect v1.2.0/go.mod h1:nwSOKmE8nU5u/CidgHtPYk1PFI3U9ignz7iDMxOYkSY= connectrpc.com/otelconnect v0.7.0 h1:ZH55ZZtcJOTKWWLy3qmL4Pam4RzRWBJFOqTPyAqCXkY= connectrpc.com/otelconnect v0.7.0/go.mod h1:Bt2ivBymHZHqxvo4HkJ0EwHuUzQN6k2l0oH+mp/8nwc= +github.com/TBD54566975/scaffolder v1.0.0 h1:QUFSy2wVzumLDg7IHcKC6AP+IYyqWe9Wxiu72nZn5qU= +github.com/TBD54566975/scaffolder v1.0.0/go.mod h1:auVpczIbOAdIhYDVSruIw41DanxOKB9bSvjf6MEl7Fs= github.com/alecthomas/assert/v2 v2.10.0 h1:jjRCHsj6hBJhkmhznrCzoNpbA3zqy0fYiUcYZP/GkPY= github.com/alecthomas/assert/v2 v2.10.0/go.mod h1:Bze95FyfUr7x34QZrjL+XP+0qgp/zg8yS+TtBj1WA3k= github.com/alecthomas/concurrency v0.0.2 h1:Q3kGPtLbleMbH9lHX5OBFvJygfyFw29bXZKBg+IEVuo= @@ -62,6 +64,8 @@ github.com/multiformats/go-base36 v0.2.0 h1:lFsAbNOGeKtuKozrtBsAkSVhv1p9D0/qedU9 github.com/multiformats/go-base36 v0.2.0/go.mod h1:qvnKE++v+2MWCfePClUEjE78Z7P2a1UV0xHgWc0hkp4= github.com/ncruces/go-strftime v0.1.9 h1:bY0MQC28UADQmHmaF5dgpLmImcShSi2kHU9XLdhx/f4= github.com/ncruces/go-strftime v0.1.9/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls= +github.com/otiai10/copy v1.14.0 h1:dCI/t1iTdYGtkvCuBG2BgR6KZa83PTclw4U5n2wAllU= +github.com/otiai10/copy v1.14.0/go.mod h1:ECfuL02W+/FkTWZWgQqXPWZgW9oeKCSQ5qVfSc4qc4w= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE= diff --git a/ftl-project.toml b/ftl-project.toml index da3d2836ff..398baf1d2b 100644 --- a/ftl-project.toml +++ b/ftl-project.toml @@ -1,12 +1,18 @@ module-dirs = ["examples/go"] external-dirs = [] +ftl-min-version = "" [global] + [global.configuration] + key = "inline://InZhbHVlIg" [modules] [modules.echo] [modules.echo.configuration] default = "inline://ImFub255bW91cyI" +[executables] + ftl = "" + [commands] startup = ["echo 'FTL startup command ⚡️'"] diff --git a/go-runtime/compile/compile_integration_test.go b/go-runtime/compile/compile_integration_test.go new file mode 100644 index 0000000000..99980cbc87 --- /dev/null +++ b/go-runtime/compile/compile_integration_test.go @@ -0,0 +1,35 @@ +//go:build integration + +package compile_test + +import ( + "testing" + + in "github.com/TBD54566975/ftl/integration" +) + +func TestNonExportedDecls(t *testing.T) { + in.Run(t, "", + in.CopyModule("time"), + in.Deploy("time"), + in.CopyModule("echo"), + in.Deploy("echo"), + in.CopyModule("notexportedverb"), + in.ExpectError( + in.ExecWithOutput("ftl", "deploy", "notexportedverb"), + "call first argument must be a function but is an unresolved reference to echo.Echo, does it need to be exported?"), + ) +} + +func TestUndefinedExportedDecls(t *testing.T) { + in.Run(t, "", + in.CopyModule("time"), + in.Deploy("time"), + in.CopyModule("echo"), + in.Deploy("echo"), + in.CopyModule("undefinedverb"), + in.ExpectError( + in.ExecWithOutput("ftl", "deploy", "undefinedverb"), + "call first argument must be a function but is an unresolved reference to echo.Undefined"), + ) +} diff --git a/go-runtime/compile/testdata/failing/go.sum b/go-runtime/compile/testdata/failing/go.sum index d823b5af4a..d4b84ece19 100644 --- a/go-runtime/compile/testdata/failing/go.sum +++ b/go-runtime/compile/testdata/failing/go.sum @@ -4,6 +4,8 @@ connectrpc.com/grpcreflect v1.2.0 h1:Q6og1S7HinmtbEuBvARLNwYmTbhEGRpHDhqrPNlmK+U connectrpc.com/grpcreflect v1.2.0/go.mod h1:nwSOKmE8nU5u/CidgHtPYk1PFI3U9ignz7iDMxOYkSY= connectrpc.com/otelconnect v0.7.0 h1:ZH55ZZtcJOTKWWLy3qmL4Pam4RzRWBJFOqTPyAqCXkY= connectrpc.com/otelconnect v0.7.0/go.mod h1:Bt2ivBymHZHqxvo4HkJ0EwHuUzQN6k2l0oH+mp/8nwc= +github.com/TBD54566975/scaffolder v1.0.0 h1:QUFSy2wVzumLDg7IHcKC6AP+IYyqWe9Wxiu72nZn5qU= +github.com/TBD54566975/scaffolder v1.0.0/go.mod h1:auVpczIbOAdIhYDVSruIw41DanxOKB9bSvjf6MEl7Fs= github.com/alecthomas/assert/v2 v2.10.0 h1:jjRCHsj6hBJhkmhznrCzoNpbA3zqy0fYiUcYZP/GkPY= github.com/alecthomas/assert/v2 v2.10.0/go.mod h1:Bze95FyfUr7x34QZrjL+XP+0qgp/zg8yS+TtBj1WA3k= github.com/alecthomas/concurrency v0.0.2 h1:Q3kGPtLbleMbH9lHX5OBFvJygfyFw29bXZKBg+IEVuo= @@ -62,6 +64,8 @@ github.com/multiformats/go-base36 v0.2.0 h1:lFsAbNOGeKtuKozrtBsAkSVhv1p9D0/qedU9 github.com/multiformats/go-base36 v0.2.0/go.mod h1:qvnKE++v+2MWCfePClUEjE78Z7P2a1UV0xHgWc0hkp4= github.com/ncruces/go-strftime v0.1.9 h1:bY0MQC28UADQmHmaF5dgpLmImcShSi2kHU9XLdhx/f4= github.com/ncruces/go-strftime v0.1.9/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls= +github.com/otiai10/copy v1.14.0 h1:dCI/t1iTdYGtkvCuBG2BgR6KZa83PTclw4U5n2wAllU= +github.com/otiai10/copy v1.14.0/go.mod h1:ECfuL02W+/FkTWZWgQqXPWZgW9oeKCSQ5qVfSc4qc4w= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE= diff --git a/integration/testdata/go/echo/echo.go b/go-runtime/compile/testdata/go/echo/echo.go similarity index 100% rename from integration/testdata/go/echo/echo.go rename to go-runtime/compile/testdata/go/echo/echo.go diff --git a/integration/testdata/go/echo/ftl.toml b/go-runtime/compile/testdata/go/echo/ftl.toml similarity index 100% rename from integration/testdata/go/echo/ftl.toml rename to go-runtime/compile/testdata/go/echo/ftl.toml diff --git a/integration/testdata/go/echo/go.mod b/go-runtime/compile/testdata/go/echo/go.mod similarity index 96% rename from integration/testdata/go/echo/go.mod rename to go-runtime/compile/testdata/go/echo/go.mod index e3ff03fb1d..b8e2142d05 100644 --- a/integration/testdata/go/echo/go.mod +++ b/go-runtime/compile/testdata/go/echo/go.mod @@ -2,7 +2,7 @@ module ftl/echo go 1.22.2 -replace github.com/TBD54566975/ftl => ../../../.. +replace github.com/TBD54566975/ftl => ./../../../../.. require github.com/TBD54566975/ftl v0.0.0-00010101000000-000000000000 diff --git a/integration/testdata/go/fsmretry/go.sum b/go-runtime/compile/testdata/go/echo/go.sum similarity index 100% rename from integration/testdata/go/fsmretry/go.sum rename to go-runtime/compile/testdata/go/echo/go.sum diff --git a/integration/testdata/go/notexportedverb/ftl.toml b/go-runtime/compile/testdata/go/notexportedverb/ftl.toml similarity index 100% rename from integration/testdata/go/notexportedverb/ftl.toml rename to go-runtime/compile/testdata/go/notexportedverb/ftl.toml diff --git a/integration/testdata/go/undefinedverb/go.mod b/go-runtime/compile/testdata/go/notexportedverb/go.mod similarity index 96% rename from integration/testdata/go/undefinedverb/go.mod rename to go-runtime/compile/testdata/go/notexportedverb/go.mod index 3936101cb3..a5a2537656 100644 --- a/integration/testdata/go/undefinedverb/go.mod +++ b/go-runtime/compile/testdata/go/notexportedverb/go.mod @@ -40,4 +40,4 @@ require ( google.golang.org/protobuf v1.34.1 // indirect ) -replace github.com/TBD54566975/ftl => ../../../.. +replace github.com/TBD54566975/ftl => ./../../../../.. diff --git a/integration/testdata/go/notexportedverb/go.sum b/go-runtime/compile/testdata/go/notexportedverb/go.sum similarity index 100% rename from integration/testdata/go/notexportedverb/go.sum rename to go-runtime/compile/testdata/go/notexportedverb/go.sum diff --git a/integration/testdata/go/notexportedverb/notexportedverb.go b/go-runtime/compile/testdata/go/notexportedverb/notexportedverb.go similarity index 100% rename from integration/testdata/go/notexportedverb/notexportedverb.go rename to go-runtime/compile/testdata/go/notexportedverb/notexportedverb.go diff --git a/integration/testdata/go/time/ftl.toml b/go-runtime/compile/testdata/go/time/ftl.toml similarity index 100% rename from integration/testdata/go/time/ftl.toml rename to go-runtime/compile/testdata/go/time/ftl.toml diff --git a/go-runtime/compile/testdata/go/time/go.mod b/go-runtime/compile/testdata/go/time/go.mod new file mode 100644 index 0000000000..406abdfc9a --- /dev/null +++ b/go-runtime/compile/testdata/go/time/go.mod @@ -0,0 +1,5 @@ +module ftl/time + +go 1.22.2 + +replace github.com/TBD54566975/ftl => ./../../../../.. diff --git a/integration/testdata/go/time/go.sum b/go-runtime/compile/testdata/go/time/go.sum similarity index 100% rename from integration/testdata/go/time/go.sum rename to go-runtime/compile/testdata/go/time/go.sum diff --git a/integration/testdata/go/time/time.go b/go-runtime/compile/testdata/go/time/time.go similarity index 100% rename from integration/testdata/go/time/time.go rename to go-runtime/compile/testdata/go/time/time.go diff --git a/integration/testdata/go/undefinedverb/ftl.toml b/go-runtime/compile/testdata/go/undefinedverb/ftl.toml similarity index 100% rename from integration/testdata/go/undefinedverb/ftl.toml rename to go-runtime/compile/testdata/go/undefinedverb/ftl.toml diff --git a/integration/testdata/go/notexportedverb/go.mod b/go-runtime/compile/testdata/go/undefinedverb/go.mod similarity index 96% rename from integration/testdata/go/notexportedverb/go.mod rename to go-runtime/compile/testdata/go/undefinedverb/go.mod index 3936101cb3..a5a2537656 100644 --- a/integration/testdata/go/notexportedverb/go.mod +++ b/go-runtime/compile/testdata/go/undefinedverb/go.mod @@ -40,4 +40,4 @@ require ( google.golang.org/protobuf v1.34.1 // indirect ) -replace github.com/TBD54566975/ftl => ../../../.. +replace github.com/TBD54566975/ftl => ./../../../../.. diff --git a/integration/testdata/go/omitempty/go.sum b/go-runtime/compile/testdata/go/undefinedverb/go.sum similarity index 100% rename from integration/testdata/go/omitempty/go.sum rename to go-runtime/compile/testdata/go/undefinedverb/go.sum diff --git a/integration/testdata/go/undefinedverb/undefinedverb.go b/go-runtime/compile/testdata/go/undefinedverb/undefinedverb.go similarity index 100% rename from integration/testdata/go/undefinedverb/undefinedverb.go rename to go-runtime/compile/testdata/go/undefinedverb/undefinedverb.go diff --git a/go-runtime/compile/testdata/one/go.sum b/go-runtime/compile/testdata/one/go.sum index d823b5af4a..d4b84ece19 100644 --- a/go-runtime/compile/testdata/one/go.sum +++ b/go-runtime/compile/testdata/one/go.sum @@ -4,6 +4,8 @@ connectrpc.com/grpcreflect v1.2.0 h1:Q6og1S7HinmtbEuBvARLNwYmTbhEGRpHDhqrPNlmK+U connectrpc.com/grpcreflect v1.2.0/go.mod h1:nwSOKmE8nU5u/CidgHtPYk1PFI3U9ignz7iDMxOYkSY= connectrpc.com/otelconnect v0.7.0 h1:ZH55ZZtcJOTKWWLy3qmL4Pam4RzRWBJFOqTPyAqCXkY= connectrpc.com/otelconnect v0.7.0/go.mod h1:Bt2ivBymHZHqxvo4HkJ0EwHuUzQN6k2l0oH+mp/8nwc= +github.com/TBD54566975/scaffolder v1.0.0 h1:QUFSy2wVzumLDg7IHcKC6AP+IYyqWe9Wxiu72nZn5qU= +github.com/TBD54566975/scaffolder v1.0.0/go.mod h1:auVpczIbOAdIhYDVSruIw41DanxOKB9bSvjf6MEl7Fs= github.com/alecthomas/assert/v2 v2.10.0 h1:jjRCHsj6hBJhkmhznrCzoNpbA3zqy0fYiUcYZP/GkPY= github.com/alecthomas/assert/v2 v2.10.0/go.mod h1:Bze95FyfUr7x34QZrjL+XP+0qgp/zg8yS+TtBj1WA3k= github.com/alecthomas/concurrency v0.0.2 h1:Q3kGPtLbleMbH9lHX5OBFvJygfyFw29bXZKBg+IEVuo= @@ -62,6 +64,8 @@ github.com/multiformats/go-base36 v0.2.0 h1:lFsAbNOGeKtuKozrtBsAkSVhv1p9D0/qedU9 github.com/multiformats/go-base36 v0.2.0/go.mod h1:qvnKE++v+2MWCfePClUEjE78Z7P2a1UV0xHgWc0hkp4= github.com/ncruces/go-strftime v0.1.9 h1:bY0MQC28UADQmHmaF5dgpLmImcShSi2kHU9XLdhx/f4= github.com/ncruces/go-strftime v0.1.9/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls= +github.com/otiai10/copy v1.14.0 h1:dCI/t1iTdYGtkvCuBG2BgR6KZa83PTclw4U5n2wAllU= +github.com/otiai10/copy v1.14.0/go.mod h1:ECfuL02W+/FkTWZWgQqXPWZgW9oeKCSQ5qVfSc4qc4w= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE= diff --git a/go-runtime/compile/testdata/parent/go.sum b/go-runtime/compile/testdata/parent/go.sum index d823b5af4a..d4b84ece19 100644 --- a/go-runtime/compile/testdata/parent/go.sum +++ b/go-runtime/compile/testdata/parent/go.sum @@ -4,6 +4,8 @@ connectrpc.com/grpcreflect v1.2.0 h1:Q6og1S7HinmtbEuBvARLNwYmTbhEGRpHDhqrPNlmK+U connectrpc.com/grpcreflect v1.2.0/go.mod h1:nwSOKmE8nU5u/CidgHtPYk1PFI3U9ignz7iDMxOYkSY= connectrpc.com/otelconnect v0.7.0 h1:ZH55ZZtcJOTKWWLy3qmL4Pam4RzRWBJFOqTPyAqCXkY= connectrpc.com/otelconnect v0.7.0/go.mod h1:Bt2ivBymHZHqxvo4HkJ0EwHuUzQN6k2l0oH+mp/8nwc= +github.com/TBD54566975/scaffolder v1.0.0 h1:QUFSy2wVzumLDg7IHcKC6AP+IYyqWe9Wxiu72nZn5qU= +github.com/TBD54566975/scaffolder v1.0.0/go.mod h1:auVpczIbOAdIhYDVSruIw41DanxOKB9bSvjf6MEl7Fs= github.com/alecthomas/assert/v2 v2.10.0 h1:jjRCHsj6hBJhkmhznrCzoNpbA3zqy0fYiUcYZP/GkPY= github.com/alecthomas/assert/v2 v2.10.0/go.mod h1:Bze95FyfUr7x34QZrjL+XP+0qgp/zg8yS+TtBj1WA3k= github.com/alecthomas/concurrency v0.0.2 h1:Q3kGPtLbleMbH9lHX5OBFvJygfyFw29bXZKBg+IEVuo= @@ -62,6 +64,8 @@ github.com/multiformats/go-base36 v0.2.0 h1:lFsAbNOGeKtuKozrtBsAkSVhv1p9D0/qedU9 github.com/multiformats/go-base36 v0.2.0/go.mod h1:qvnKE++v+2MWCfePClUEjE78Z7P2a1UV0xHgWc0hkp4= github.com/ncruces/go-strftime v0.1.9 h1:bY0MQC28UADQmHmaF5dgpLmImcShSi2kHU9XLdhx/f4= github.com/ncruces/go-strftime v0.1.9/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls= +github.com/otiai10/copy v1.14.0 h1:dCI/t1iTdYGtkvCuBG2BgR6KZa83PTclw4U5n2wAllU= +github.com/otiai10/copy v1.14.0/go.mod h1:ECfuL02W+/FkTWZWgQqXPWZgW9oeKCSQ5qVfSc4qc4w= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE= diff --git a/go-runtime/compile/testdata/pubsub/go.sum b/go-runtime/compile/testdata/pubsub/go.sum index d823b5af4a..d4b84ece19 100644 --- a/go-runtime/compile/testdata/pubsub/go.sum +++ b/go-runtime/compile/testdata/pubsub/go.sum @@ -4,6 +4,8 @@ connectrpc.com/grpcreflect v1.2.0 h1:Q6og1S7HinmtbEuBvARLNwYmTbhEGRpHDhqrPNlmK+U connectrpc.com/grpcreflect v1.2.0/go.mod h1:nwSOKmE8nU5u/CidgHtPYk1PFI3U9ignz7iDMxOYkSY= connectrpc.com/otelconnect v0.7.0 h1:ZH55ZZtcJOTKWWLy3qmL4Pam4RzRWBJFOqTPyAqCXkY= connectrpc.com/otelconnect v0.7.0/go.mod h1:Bt2ivBymHZHqxvo4HkJ0EwHuUzQN6k2l0oH+mp/8nwc= +github.com/TBD54566975/scaffolder v1.0.0 h1:QUFSy2wVzumLDg7IHcKC6AP+IYyqWe9Wxiu72nZn5qU= +github.com/TBD54566975/scaffolder v1.0.0/go.mod h1:auVpczIbOAdIhYDVSruIw41DanxOKB9bSvjf6MEl7Fs= github.com/alecthomas/assert/v2 v2.10.0 h1:jjRCHsj6hBJhkmhznrCzoNpbA3zqy0fYiUcYZP/GkPY= github.com/alecthomas/assert/v2 v2.10.0/go.mod h1:Bze95FyfUr7x34QZrjL+XP+0qgp/zg8yS+TtBj1WA3k= github.com/alecthomas/concurrency v0.0.2 h1:Q3kGPtLbleMbH9lHX5OBFvJygfyFw29bXZKBg+IEVuo= @@ -62,6 +64,8 @@ github.com/multiformats/go-base36 v0.2.0 h1:lFsAbNOGeKtuKozrtBsAkSVhv1p9D0/qedU9 github.com/multiformats/go-base36 v0.2.0/go.mod h1:qvnKE++v+2MWCfePClUEjE78Z7P2a1UV0xHgWc0hkp4= github.com/ncruces/go-strftime v0.1.9 h1:bY0MQC28UADQmHmaF5dgpLmImcShSi2kHU9XLdhx/f4= github.com/ncruces/go-strftime v0.1.9/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls= +github.com/otiai10/copy v1.14.0 h1:dCI/t1iTdYGtkvCuBG2BgR6KZa83PTclw4U5n2wAllU= +github.com/otiai10/copy v1.14.0/go.mod h1:ECfuL02W+/FkTWZWgQqXPWZgW9oeKCSQ5qVfSc4qc4w= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE= diff --git a/go-runtime/compile/testdata/subscriber/go.sum b/go-runtime/compile/testdata/subscriber/go.sum index d823b5af4a..d4b84ece19 100644 --- a/go-runtime/compile/testdata/subscriber/go.sum +++ b/go-runtime/compile/testdata/subscriber/go.sum @@ -4,6 +4,8 @@ connectrpc.com/grpcreflect v1.2.0 h1:Q6og1S7HinmtbEuBvARLNwYmTbhEGRpHDhqrPNlmK+U connectrpc.com/grpcreflect v1.2.0/go.mod h1:nwSOKmE8nU5u/CidgHtPYk1PFI3U9ignz7iDMxOYkSY= connectrpc.com/otelconnect v0.7.0 h1:ZH55ZZtcJOTKWWLy3qmL4Pam4RzRWBJFOqTPyAqCXkY= connectrpc.com/otelconnect v0.7.0/go.mod h1:Bt2ivBymHZHqxvo4HkJ0EwHuUzQN6k2l0oH+mp/8nwc= +github.com/TBD54566975/scaffolder v1.0.0 h1:QUFSy2wVzumLDg7IHcKC6AP+IYyqWe9Wxiu72nZn5qU= +github.com/TBD54566975/scaffolder v1.0.0/go.mod h1:auVpczIbOAdIhYDVSruIw41DanxOKB9bSvjf6MEl7Fs= github.com/alecthomas/assert/v2 v2.10.0 h1:jjRCHsj6hBJhkmhznrCzoNpbA3zqy0fYiUcYZP/GkPY= github.com/alecthomas/assert/v2 v2.10.0/go.mod h1:Bze95FyfUr7x34QZrjL+XP+0qgp/zg8yS+TtBj1WA3k= github.com/alecthomas/concurrency v0.0.2 h1:Q3kGPtLbleMbH9lHX5OBFvJygfyFw29bXZKBg+IEVuo= @@ -62,6 +64,8 @@ github.com/multiformats/go-base36 v0.2.0 h1:lFsAbNOGeKtuKozrtBsAkSVhv1p9D0/qedU9 github.com/multiformats/go-base36 v0.2.0/go.mod h1:qvnKE++v+2MWCfePClUEjE78Z7P2a1UV0xHgWc0hkp4= github.com/ncruces/go-strftime v0.1.9 h1:bY0MQC28UADQmHmaF5dgpLmImcShSi2kHU9XLdhx/f4= github.com/ncruces/go-strftime v0.1.9/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls= +github.com/otiai10/copy v1.14.0 h1:dCI/t1iTdYGtkvCuBG2BgR6KZa83PTclw4U5n2wAllU= +github.com/otiai10/copy v1.14.0/go.mod h1:ECfuL02W+/FkTWZWgQqXPWZgW9oeKCSQ5qVfSc4qc4w= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE= diff --git a/go-runtime/compile/testdata/two/go.sum b/go-runtime/compile/testdata/two/go.sum index d823b5af4a..d4b84ece19 100644 --- a/go-runtime/compile/testdata/two/go.sum +++ b/go-runtime/compile/testdata/two/go.sum @@ -4,6 +4,8 @@ connectrpc.com/grpcreflect v1.2.0 h1:Q6og1S7HinmtbEuBvARLNwYmTbhEGRpHDhqrPNlmK+U connectrpc.com/grpcreflect v1.2.0/go.mod h1:nwSOKmE8nU5u/CidgHtPYk1PFI3U9ignz7iDMxOYkSY= connectrpc.com/otelconnect v0.7.0 h1:ZH55ZZtcJOTKWWLy3qmL4Pam4RzRWBJFOqTPyAqCXkY= connectrpc.com/otelconnect v0.7.0/go.mod h1:Bt2ivBymHZHqxvo4HkJ0EwHuUzQN6k2l0oH+mp/8nwc= +github.com/TBD54566975/scaffolder v1.0.0 h1:QUFSy2wVzumLDg7IHcKC6AP+IYyqWe9Wxiu72nZn5qU= +github.com/TBD54566975/scaffolder v1.0.0/go.mod h1:auVpczIbOAdIhYDVSruIw41DanxOKB9bSvjf6MEl7Fs= github.com/alecthomas/assert/v2 v2.10.0 h1:jjRCHsj6hBJhkmhznrCzoNpbA3zqy0fYiUcYZP/GkPY= github.com/alecthomas/assert/v2 v2.10.0/go.mod h1:Bze95FyfUr7x34QZrjL+XP+0qgp/zg8yS+TtBj1WA3k= github.com/alecthomas/concurrency v0.0.2 h1:Q3kGPtLbleMbH9lHX5OBFvJygfyFw29bXZKBg+IEVuo= @@ -62,6 +64,8 @@ github.com/multiformats/go-base36 v0.2.0 h1:lFsAbNOGeKtuKozrtBsAkSVhv1p9D0/qedU9 github.com/multiformats/go-base36 v0.2.0/go.mod h1:qvnKE++v+2MWCfePClUEjE78Z7P2a1UV0xHgWc0hkp4= github.com/ncruces/go-strftime v0.1.9 h1:bY0MQC28UADQmHmaF5dgpLmImcShSi2kHU9XLdhx/f4= github.com/ncruces/go-strftime v0.1.9/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls= +github.com/otiai10/copy v1.14.0 h1:dCI/t1iTdYGtkvCuBG2BgR6KZa83PTclw4U5n2wAllU= +github.com/otiai10/copy v1.14.0/go.mod h1:ECfuL02W+/FkTWZWgQqXPWZgW9oeKCSQ5qVfSc4qc4w= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE= diff --git a/go-runtime/encoding/encoding_integration_test.go b/go-runtime/encoding/encoding_integration_test.go new file mode 100644 index 0000000000..b3dea04d91 --- /dev/null +++ b/go-runtime/encoding/encoding_integration_test.go @@ -0,0 +1,25 @@ +//go:build integration + +package encoding_test + +import ( + "net/http" + "testing" + + in "github.com/TBD54566975/ftl/integration" + "github.com/alecthomas/assert/v2" +) + +func TestHttpEncodeOmitempty(t *testing.T) { + in.Run(t, "", + in.CopyModule("omitempty"), + in.Deploy("omitempty"), + in.HttpCall(http.MethodGet, "/get", in.JsonData(t, in.Obj{}), func(t testing.TB, resp *in.HTTPResponse) { + assert.Equal(t, 200, resp.Status) + _, ok := resp.JsonBody["mustset"] + assert.True(t, ok) + _, ok = resp.JsonBody["error"] + assert.False(t, ok) + }), + ) +} diff --git a/integration/testdata/go/omitempty/ftl.toml b/go-runtime/encoding/testdata/go/omitempty/ftl.toml similarity index 100% rename from integration/testdata/go/omitempty/ftl.toml rename to go-runtime/encoding/testdata/go/omitempty/ftl.toml diff --git a/integration/testdata/go/omitempty/go.mod b/go-runtime/encoding/testdata/go/omitempty/go.mod similarity index 96% rename from integration/testdata/go/omitempty/go.mod rename to go-runtime/encoding/testdata/go/omitempty/go.mod index f65b4428c6..40e422ae44 100644 --- a/integration/testdata/go/omitempty/go.mod +++ b/go-runtime/encoding/testdata/go/omitempty/go.mod @@ -40,4 +40,4 @@ require ( google.golang.org/protobuf v1.34.1 // indirect ) -replace github.com/TBD54566975/ftl => ../../../.. +replace github.com/TBD54566975/ftl => ./../../../../.. diff --git a/integration/testdata/go/runtimereflection/go.sum b/go-runtime/encoding/testdata/go/omitempty/go.sum similarity index 100% rename from integration/testdata/go/runtimereflection/go.sum rename to go-runtime/encoding/testdata/go/omitempty/go.sum diff --git a/integration/testdata/go/omitempty/omitempty.go b/go-runtime/encoding/testdata/go/omitempty/omitempty.go similarity index 93% rename from integration/testdata/go/omitempty/omitempty.go rename to go-runtime/encoding/testdata/go/omitempty/omitempty.go index e0abf0e1ec..5685c54f95 100644 --- a/integration/testdata/go/omitempty/omitempty.go +++ b/go-runtime/encoding/testdata/go/omitempty/omitempty.go @@ -19,6 +19,6 @@ type Response struct { func Get(ctx context.Context, req builtin.HttpRequest[Request]) (builtin.HttpResponse[Response, string], error) { return builtin.HttpResponse[Response, string]{ Headers: map[string][]string{"Get": {"Header from FTL"}}, - Body: ftl.Some[Response](Response{}), + Body: ftl.Some[Response](Response{}), }, nil } diff --git a/go-runtime/ftl/ftl_integration_test.go b/go-runtime/ftl/ftl_integration_test.go new file mode 100644 index 0000000000..44da186b85 --- /dev/null +++ b/go-runtime/ftl/ftl_integration_test.go @@ -0,0 +1,48 @@ +//go:build integration + +package ftl_test + +import ( + "strings" + "testing" + + in "github.com/TBD54566975/ftl/integration" + "github.com/alecthomas/assert/v2" + + "github.com/alecthomas/repr" +) + +func TestLifecycle(t *testing.T) { + in.Run(t, "", + in.Exec("ftl", "init", "go", ".", "echo"), + in.Deploy("echo"), + in.Call("echo", "echo", in.Obj{"name": "Bob"}, func(t testing.TB, response in.Obj) { + assert.Equal(t, "Hello, Bob!", response["message"]) + }), + ) +} + +func TestInterModuleCall(t *testing.T) { + in.Run(t, "", + in.CopyModule("echo"), + in.CopyModule("time"), + in.Deploy("time"), + in.Deploy("echo"), + in.Call("echo", "echo", in.Obj{"name": "Bob"}, func(t testing.TB, response in.Obj) { + message, ok := response["message"].(string) + assert.True(t, ok, "message is not a string: %s", repr.String(response)) + if !strings.HasPrefix(message, "Hello, Bob!!! It is ") { + t.Fatalf("unexpected response: %q", response) + } + }), + ) +} + +func TestSchemaGenerate(t *testing.T) { + in.Run(t, "", + in.CopyDir("../schema-generate", "schema-generate"), + in.Mkdir("build/schema-generate"), + in.Exec("ftl", "schema", "generate", "schema-generate", "build/schema-generate"), + in.FileContains("build/schema-generate/test.txt", "olleh"), + ) +} diff --git a/go-runtime/ftl/ftltest/ftltest_integration_test.go b/go-runtime/ftl/ftltest/ftltest_integration_test.go new file mode 100644 index 0000000000..c6665019c7 --- /dev/null +++ b/go-runtime/ftl/ftltest/ftltest_integration_test.go @@ -0,0 +1,20 @@ +//go:build integration + +package ftltest + +import ( + "testing" + + in "github.com/TBD54566975/ftl/integration" +) + +func TestModuleUnitTests(t *testing.T) { + in.Run(t, "", + in.CopyModule("time"), + in.CopyModule("wrapped"), + in.CopyModule("verbtypes"), + in.Build("time", "wrapped", "verbtypes"), + in.ExecModuleTest("wrapped"), + in.ExecModuleTest("verbtypes"), + ) +} diff --git a/go-runtime/ftl/ftltest/testdata/go/time/ftl.toml b/go-runtime/ftl/ftltest/testdata/go/time/ftl.toml new file mode 100644 index 0000000000..c7449d155e --- /dev/null +++ b/go-runtime/ftl/ftltest/testdata/go/time/ftl.toml @@ -0,0 +1,5 @@ +module = "time" +language = "go" + +[go.replace] +"github.com/TBD54566975/ftl" = "../.." diff --git a/go-runtime/ftl/ftltest/testdata/go/time/go.mod b/go-runtime/ftl/ftltest/testdata/go/time/go.mod new file mode 100644 index 0000000000..b4b3d82a9e --- /dev/null +++ b/go-runtime/ftl/ftltest/testdata/go/time/go.mod @@ -0,0 +1,5 @@ +module ftl/time + +go 1.22.2 + +replace github.com/TBD54566975/ftl => ./../../../../../.. diff --git a/go-runtime/ftl/ftltest/testdata/go/time/go.sum b/go-runtime/ftl/ftltest/testdata/go/time/go.sum new file mode 100644 index 0000000000..e69de29bb2 diff --git a/go-runtime/ftl/ftltest/testdata/go/time/time.go b/go-runtime/ftl/ftltest/testdata/go/time/time.go new file mode 100644 index 0000000000..e18f7c0e26 --- /dev/null +++ b/go-runtime/ftl/ftltest/testdata/go/time/time.go @@ -0,0 +1,18 @@ +package time + +import ( + "context" + "time" +) + +type TimeRequest struct{} +type TimeResponse struct { + Time time.Time +} + +// Time returns the current time. +// +//ftl:verb export +func Time(ctx context.Context, req TimeRequest) (TimeResponse, error) { + return TimeResponse{Time: time.Now()}, nil +} diff --git a/integration/testdata/go/verbtypes/ftl.toml b/go-runtime/ftl/ftltest/testdata/go/verbtypes/ftl.toml similarity index 100% rename from integration/testdata/go/verbtypes/ftl.toml rename to go-runtime/ftl/ftltest/testdata/go/verbtypes/ftl.toml diff --git a/integration/testdata/go/verbtypes/go.mod b/go-runtime/ftl/ftltest/testdata/go/verbtypes/go.mod similarity index 97% rename from integration/testdata/go/verbtypes/go.mod rename to go-runtime/ftl/ftltest/testdata/go/verbtypes/go.mod index 78f97d99a1..177aa75f2f 100644 --- a/integration/testdata/go/verbtypes/go.mod +++ b/go-runtime/ftl/ftltest/testdata/go/verbtypes/go.mod @@ -7,7 +7,7 @@ require ( github.com/alecthomas/assert/v2 v2.10.0 ) -replace github.com/TBD54566975/ftl => ../../../.. +replace github.com/TBD54566975/ftl => ./../../../../../.. require ( connectrpc.com/connect v1.16.1 // indirect diff --git a/integration/testdata/go/verbtypes/go.sum b/go-runtime/ftl/ftltest/testdata/go/verbtypes/go.sum similarity index 100% rename from integration/testdata/go/verbtypes/go.sum rename to go-runtime/ftl/ftltest/testdata/go/verbtypes/go.sum diff --git a/integration/testdata/go/verbtypes/verbtypes.go b/go-runtime/ftl/ftltest/testdata/go/verbtypes/verbtypes.go similarity index 100% rename from integration/testdata/go/verbtypes/verbtypes.go rename to go-runtime/ftl/ftltest/testdata/go/verbtypes/verbtypes.go diff --git a/integration/testdata/go/verbtypes/verbtypes_test.go b/go-runtime/ftl/ftltest/testdata/go/verbtypes/verbtypes_test.go similarity index 100% rename from integration/testdata/go/verbtypes/verbtypes_test.go rename to go-runtime/ftl/ftltest/testdata/go/verbtypes/verbtypes_test.go diff --git a/integration/testdata/go/wrapped/ftl-project-test-1.toml b/go-runtime/ftl/ftltest/testdata/go/wrapped/ftl-project-test-1.toml similarity index 100% rename from integration/testdata/go/wrapped/ftl-project-test-1.toml rename to go-runtime/ftl/ftltest/testdata/go/wrapped/ftl-project-test-1.toml diff --git a/integration/testdata/go/wrapped/ftl-project-test-2.toml b/go-runtime/ftl/ftltest/testdata/go/wrapped/ftl-project-test-2.toml similarity index 100% rename from integration/testdata/go/wrapped/ftl-project-test-2.toml rename to go-runtime/ftl/ftltest/testdata/go/wrapped/ftl-project-test-2.toml diff --git a/integration/testdata/go/wrapped/ftl-project.toml b/go-runtime/ftl/ftltest/testdata/go/wrapped/ftl-project.toml similarity index 100% rename from integration/testdata/go/wrapped/ftl-project.toml rename to go-runtime/ftl/ftltest/testdata/go/wrapped/ftl-project.toml diff --git a/integration/testdata/go/wrapped/ftl.toml b/go-runtime/ftl/ftltest/testdata/go/wrapped/ftl.toml similarity index 100% rename from integration/testdata/go/wrapped/ftl.toml rename to go-runtime/ftl/ftltest/testdata/go/wrapped/ftl.toml diff --git a/integration/testdata/go/wrapped/go.mod b/go-runtime/ftl/ftltest/testdata/go/wrapped/go.mod similarity index 97% rename from integration/testdata/go/wrapped/go.mod rename to go-runtime/ftl/ftltest/testdata/go/wrapped/go.mod index e85fb7661d..63cce35141 100644 --- a/integration/testdata/go/wrapped/go.mod +++ b/go-runtime/ftl/ftltest/testdata/go/wrapped/go.mod @@ -58,4 +58,4 @@ require ( google.golang.org/protobuf v1.34.1 // indirect ) -replace github.com/TBD54566975/ftl => ../../../.. +replace github.com/TBD54566975/ftl => ./../../../../../.. diff --git a/integration/testdata/go/wrapped/go.sum b/go-runtime/ftl/ftltest/testdata/go/wrapped/go.sum similarity index 100% rename from integration/testdata/go/wrapped/go.sum rename to go-runtime/ftl/ftltest/testdata/go/wrapped/go.sum diff --git a/integration/testdata/go/wrapped/wrapped.go b/go-runtime/ftl/ftltest/testdata/go/wrapped/wrapped.go similarity index 100% rename from integration/testdata/go/wrapped/wrapped.go rename to go-runtime/ftl/ftltest/testdata/go/wrapped/wrapped.go diff --git a/integration/testdata/go/wrapped/wrapped_test.go b/go-runtime/ftl/ftltest/testdata/go/wrapped/wrapped_test.go similarity index 100% rename from integration/testdata/go/wrapped/wrapped_test.go rename to go-runtime/ftl/ftltest/testdata/go/wrapped/wrapped_test.go diff --git a/go-runtime/ftl/reflection/reflection_integration_test.go b/go-runtime/ftl/reflection/reflection_integration_test.go new file mode 100644 index 0000000000..e858feefc3 --- /dev/null +++ b/go-runtime/ftl/reflection/reflection_integration_test.go @@ -0,0 +1,16 @@ +//go:build integration + +package reflection_test + +import ( + "testing" + + in "github.com/TBD54566975/ftl/integration" +) + +func TestRuntimeReflection(t *testing.T) { + in.Run(t, "", + in.CopyModule("runtimereflection"), + in.ExecModuleTest("runtimereflection"), + ) +} diff --git a/integration/testdata/go/runtimereflection/ftl.toml b/go-runtime/ftl/reflection/testdata/go/runtimereflection/ftl.toml similarity index 100% rename from integration/testdata/go/runtimereflection/ftl.toml rename to go-runtime/ftl/reflection/testdata/go/runtimereflection/ftl.toml diff --git a/integration/testdata/go/runtimereflection/go.mod b/go-runtime/ftl/reflection/testdata/go/runtimereflection/go.mod similarity index 96% rename from integration/testdata/go/runtimereflection/go.mod rename to go-runtime/ftl/reflection/testdata/go/runtimereflection/go.mod index 48a5769d97..b07cdab8db 100644 --- a/integration/testdata/go/runtimereflection/go.mod +++ b/go-runtime/ftl/reflection/testdata/go/runtimereflection/go.mod @@ -45,4 +45,4 @@ require ( google.golang.org/protobuf v1.34.1 // indirect ) -replace github.com/TBD54566975/ftl => ../../../.. +replace github.com/TBD54566975/ftl => ./../../../../../.. diff --git a/integration/testdata/go/undefinedverb/go.sum b/go-runtime/ftl/reflection/testdata/go/runtimereflection/go.sum similarity index 100% rename from integration/testdata/go/undefinedverb/go.sum rename to go-runtime/ftl/reflection/testdata/go/runtimereflection/go.sum diff --git a/integration/testdata/go/runtimereflection/runtimereflection.go b/go-runtime/ftl/reflection/testdata/go/runtimereflection/runtimereflection.go similarity index 100% rename from integration/testdata/go/runtimereflection/runtimereflection.go rename to go-runtime/ftl/reflection/testdata/go/runtimereflection/runtimereflection.go diff --git a/integration/testdata/go/runtimereflection/runtimereflection_test.go b/go-runtime/ftl/reflection/testdata/go/runtimereflection/runtimereflection_test.go similarity index 100% rename from integration/testdata/go/runtimereflection/runtimereflection_test.go rename to go-runtime/ftl/reflection/testdata/go/runtimereflection/runtimereflection_test.go diff --git a/go-runtime/ftl/testdata/go/echo/echo.go b/go-runtime/ftl/testdata/go/echo/echo.go new file mode 100644 index 0000000000..233b4850cb --- /dev/null +++ b/go-runtime/ftl/testdata/go/echo/echo.go @@ -0,0 +1,34 @@ +// This is the echo module. +package echo + +import ( + "context" + "fmt" + + "ftl/time" + + "github.com/TBD54566975/ftl/go-runtime/ftl" +) + +var defaultName = ftl.Config[string]("default") + +// An echo request. +type EchoRequest struct { + Name ftl.Option[string] `json:"name"` +} + +type EchoResponse struct { + Message string `json:"message"` +} + +// Echo returns a greeting with the current time. +// +//ftl:verb +func Echo(ctx context.Context, req EchoRequest) (EchoResponse, error) { + tresp, err := ftl.Call(ctx, time.Time, time.TimeRequest{}) + if err != nil { + return EchoResponse{}, err + } + + return EchoResponse{Message: fmt.Sprintf("Hello, %s!!! It is %s!", req.Name.Default(defaultName.Get(ctx)), tresp.Time)}, nil +} diff --git a/go-runtime/ftl/testdata/go/echo/ftl.toml b/go-runtime/ftl/testdata/go/echo/ftl.toml new file mode 100644 index 0000000000..72ce292aa2 --- /dev/null +++ b/go-runtime/ftl/testdata/go/echo/ftl.toml @@ -0,0 +1,2 @@ +module = "echo" +language = "go" diff --git a/go-runtime/ftl/testdata/go/echo/go.mod b/go-runtime/ftl/testdata/go/echo/go.mod new file mode 100644 index 0000000000..b8e2142d05 --- /dev/null +++ b/go-runtime/ftl/testdata/go/echo/go.mod @@ -0,0 +1,43 @@ +module ftl/echo + +go 1.22.2 + +replace github.com/TBD54566975/ftl => ./../../../../.. + +require github.com/TBD54566975/ftl v0.0.0-00010101000000-000000000000 + +require ( + connectrpc.com/connect v1.16.1 // indirect + connectrpc.com/grpcreflect v1.2.0 // indirect + connectrpc.com/otelconnect v0.7.0 // indirect + github.com/alecthomas/concurrency v0.0.2 // indirect + github.com/alecthomas/participle/v2 v2.1.1 // indirect + github.com/alecthomas/types v0.16.0 // indirect + github.com/alessio/shellescape v1.4.2 // 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/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/swaggest/jsonschema-go v0.3.70 // indirect + github.com/swaggest/refl v1.3.0 // indirect + github.com/zalando/go-keyring v0.2.4 // 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.23.0 // indirect + golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 // indirect + golang.org/x/mod v0.17.0 // indirect + golang.org/x/net v0.25.0 // indirect + golang.org/x/sync v0.7.0 // indirect + golang.org/x/sys v0.20.0 // indirect + golang.org/x/text v0.15.0 // indirect + google.golang.org/protobuf v1.34.1 // indirect +) diff --git a/go-runtime/ftl/testdata/go/echo/go.sum b/go-runtime/ftl/testdata/go/echo/go.sum new file mode 100644 index 0000000000..d823b5af4a --- /dev/null +++ b/go-runtime/ftl/testdata/go/echo/go.sum @@ -0,0 +1,136 @@ +connectrpc.com/connect v1.16.1 h1:rOdrK/RTI/7TVnn3JsVxt3n028MlTRwmK5Q4heSpjis= +connectrpc.com/connect v1.16.1/go.mod h1:XpZAduBQUySsb4/KO5JffORVkDI4B6/EYPi7N8xpNZw= +connectrpc.com/grpcreflect v1.2.0 h1:Q6og1S7HinmtbEuBvARLNwYmTbhEGRpHDhqrPNlmK+U= +connectrpc.com/grpcreflect v1.2.0/go.mod h1:nwSOKmE8nU5u/CidgHtPYk1PFI3U9ignz7iDMxOYkSY= +connectrpc.com/otelconnect v0.7.0 h1:ZH55ZZtcJOTKWWLy3qmL4Pam4RzRWBJFOqTPyAqCXkY= +connectrpc.com/otelconnect v0.7.0/go.mod h1:Bt2ivBymHZHqxvo4HkJ0EwHuUzQN6k2l0oH+mp/8nwc= +github.com/alecthomas/assert/v2 v2.10.0 h1:jjRCHsj6hBJhkmhznrCzoNpbA3zqy0fYiUcYZP/GkPY= +github.com/alecthomas/assert/v2 v2.10.0/go.mod h1:Bze95FyfUr7x34QZrjL+XP+0qgp/zg8yS+TtBj1WA3k= +github.com/alecthomas/concurrency v0.0.2 h1:Q3kGPtLbleMbH9lHX5OBFvJygfyFw29bXZKBg+IEVuo= +github.com/alecthomas/concurrency v0.0.2/go.mod h1:GmuQb/iHX7mbNtPlC/WDzEFxDMB0HYFer2Qda9QTs7w= +github.com/alecthomas/participle/v2 v2.1.1 h1:hrjKESvSqGHzRb4yW1ciisFJ4p3MGYih6icjJvbsmV8= +github.com/alecthomas/participle/v2 v2.1.1/go.mod h1:Y1+hAs8DHPmc3YUFzqllV+eSQ9ljPTk0ZkPMtEdAx2c= +github.com/alecthomas/repr v0.4.0 h1:GhI2A8MACjfegCPVq9f1FLvIBS+DrQ2KQBFZP1iFzXc= +github.com/alecthomas/repr v0.4.0/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4= +github.com/alecthomas/types v0.16.0 h1:o9+JSwCRB6DDaWDeR/Mg7v/zh3R+MlknM6DrnDyY7U0= +github.com/alecthomas/types v0.16.0/go.mod h1:Tswm0qQpjpVq8rn70OquRsUtFxbQKub/8TMyYYGI0+k= +github.com/alessio/shellescape v1.4.2 h1:MHPfaU+ddJ0/bYWpgIeUnQUqKrlJ1S7BfEYPM4uEoM0= +github.com/alessio/shellescape v1.4.2/go.mod h1:PZAiSCk0LJaZkiCSkPv8qIobYglO3FPpyFjDCtHLS30= +github.com/bool64/dev v0.2.34 h1:P9n315P8LdpxusnYQ0X7MP1CZXwBK5ae5RZrd+GdSZE= +github.com/bool64/dev v0.2.34/go.mod h1:iJbh1y/HkunEPhgebWRNcs8wfGq7sjvJ6W5iabL8ACg= +github.com/bool64/shared v0.1.5 h1:fp3eUhBsrSjNCQPcSdQqZxxh9bBwrYiZ+zOKFkM0/2E= +github.com/bool64/shared v0.1.5/go.mod h1:081yz68YC9jeFB3+Bbmno2RFWvGKv1lPKkMP6MHJlPs= +github.com/danieljoos/wincred v1.2.0 h1:ozqKHaLK0W/ii4KVbbvluM91W2H3Sh0BncbUNPS7jLE= +github.com/danieljoos/wincred v1.2.0/go.mod h1:FzQLLMKBFdvu+osBrnFODiv32YGwCfx0SkRa/eYHgec= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY= +github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto= +github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= +github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= +github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= +github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= +github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= +github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk= +github.com/godbus/dbus/v5 v5.1.0/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= +github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= +github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/hashicorp/golang-lru/v2 v2.0.7 h1:a+bsQ5rvGLjzHuww6tVxozPZFVghXaHOwFs4luLUK2k= +github.com/hashicorp/golang-lru/v2 v2.0.7/go.mod h1:QeFd9opnmA6QUJc5vARoKUSoFhyfM2/ZepoAG6RGpeM= +github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM= +github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg= +github.com/iancoleman/orderedmap v0.3.0 h1:5cbR2grmZR/DiVt+VJopEhtVs9YGInGIxAoMJn+Ichc= +github.com/iancoleman/orderedmap v0.3.0/go.mod h1:XuLcCUkdL5owUCQeF2Ue9uuw1EptkJDkXXS7VoV7XGE= +github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM= +github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg= +github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a h1:bbPeKD0xmW/Y25WS6cokEszi5g+S0QxI/d45PkRi7Nk= +github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM= +github.com/jackc/pgx/v5 v5.6.0 h1:SWJzexBzPL5jb0GEsrPMLIsi/3jOo7RHlzTjcAeDrPY= +github.com/jackc/pgx/v5 v5.6.0/go.mod h1:DNZ/vlrUnhWCoFGxHAG8U2ljioxukquj7utPDgtQdTw= +github.com/jackc/puddle/v2 v2.2.1 h1:RhxXJtFG022u4ibrCSMSiu5aOq1i77R3OHKNJj77OAk= +github.com/jackc/puddle/v2 v2.2.1/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4= +github.com/jpillora/backoff v1.0.0 h1:uvFg412JmmHBHw7iwprIxkPMI+sGQ4kzOWsMeHnm2EA= +github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4= +github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 h1:Z9n2FFNUXsshfwJMBgNA0RU6/i7WVaAegv3PtuIHPMs= +github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51/go.mod h1:CzGEWj7cYgsdH8dAjBGEr58BoE7ScuLd+fwFZ44+/x8= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/multiformats/go-base36 v0.2.0 h1:lFsAbNOGeKtuKozrtBsAkSVhv1p9D0/qedU9rQyccr0= +github.com/multiformats/go-base36 v0.2.0/go.mod h1:qvnKE++v+2MWCfePClUEjE78Z7P2a1UV0xHgWc0hkp4= +github.com/ncruces/go-strftime v0.1.9 h1:bY0MQC28UADQmHmaF5dgpLmImcShSi2kHU9XLdhx/f4= +github.com/ncruces/go-strftime v0.1.9/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE= +github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo= +github.com/santhosh-tekuri/jsonschema/v5 v5.3.1 h1:lZUw3E0/J3roVtGQ+SCrUrg3ON6NgVqpn3+iol9aGu4= +github.com/santhosh-tekuri/jsonschema/v5 v5.3.1/go.mod h1:uToXkOrWAZ6/Oc07xWQrPOhJotwFIyu2bBVN41fcDUY= +github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8= +github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY= +github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/swaggest/assertjson v1.9.0 h1:dKu0BfJkIxv/xe//mkCrK5yZbs79jL7OVf9Ija7o2xQ= +github.com/swaggest/assertjson v1.9.0/go.mod h1:b+ZKX2VRiUjxfUIal0HDN85W0nHPAYUbYH5WkkSsFsU= +github.com/swaggest/jsonschema-go v0.3.70 h1:8Vx5nm5t/6DBFw2+WC0/Vp1ZVe9/4mpuA0tuAe0wwCI= +github.com/swaggest/jsonschema-go v0.3.70/go.mod h1:7N43/CwdaWgPUDfYV70K7Qm79tRqe/al7gLSt9YeGIE= +github.com/swaggest/refl v1.3.0 h1:PEUWIku+ZznYfsoyheF97ypSduvMApYyGkYF3nabS0I= +github.com/swaggest/refl v1.3.0/go.mod h1:3Ujvbmh1pfSbDYjC6JGG7nMgPvpG0ehQL4iNonnLNbg= +github.com/yudai/gojsondiff v1.0.0 h1:27cbfqXLVEJ1o8I6v3y9lg8Ydm53EKqHXAOMxEGlCOA= +github.com/yudai/gojsondiff v1.0.0/go.mod h1:AY32+k2cwILAkW1fbgxQ5mUmMiZFgLIV+FBNExI05xg= +github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82 h1:BHyfKlQyqbsFN5p3IfnEUduWvb9is428/nNb5L3U01M= +github.com/yudai/golcs v0.0.0-20170316035057-ecda9a501e82/go.mod h1:lgjkn3NuSvDfVJdfcVVdX+jpBxNmX4rDAzaS45IcYoM= +github.com/zalando/go-keyring v0.2.4 h1:wi2xxTqdiwMKbM6TWwi+uJCG/Tum2UV0jqaQhCa9/68= +github.com/zalando/go-keyring v0.2.4/go.mod h1:HL4k+OXQfJUWaMnqyuSOc0drfGPX2b51Du6K+MRgZMk= +go.opentelemetry.io/otel v1.27.0 h1:9BZoF3yMK/O1AafMiQTVu0YDj5Ea4hPhxCs7sGva+cg= +go.opentelemetry.io/otel v1.27.0/go.mod h1:DMpAK8fzYRzs+bi3rS5REupisuqTheUlSZJ1WnZaPAQ= +go.opentelemetry.io/otel/metric v1.27.0 h1:hvj3vdEKyeCi4YaYfNjv2NUje8FqKqUY8IlF0FxV/ik= +go.opentelemetry.io/otel/metric v1.27.0/go.mod h1:mVFgmRlhljgBiuk/MP/oKylr4hs85GZAylncepAX/ak= +go.opentelemetry.io/otel/sdk v1.27.0 h1:mlk+/Y1gLPLn84U4tI8d3GNJmGT/eXe3ZuOXN9kTWmI= +go.opentelemetry.io/otel/sdk v1.27.0/go.mod h1:Ha9vbLwJE6W86YstIywK2xFfPjbWlCuwPtMkKdz/Y4A= +go.opentelemetry.io/otel/sdk/metric v1.27.0 h1:5uGNOlpXi+Hbo/DRoI31BSb1v+OGcpv2NemcCrOL8gI= +go.opentelemetry.io/otel/sdk/metric v1.27.0/go.mod h1:we7jJVrYN2kh3mVBlswtPU22K0SA+769l93J6bsyvqw= +go.opentelemetry.io/otel/trace v1.27.0 h1:IqYb813p7cmbHk0a5y6pD5JPakbVfftRXABGt5/Rscw= +go.opentelemetry.io/otel/trace v1.27.0/go.mod h1:6RiD1hkAprV4/q+yd2ln1HG9GoPx39SuvvstaLBl+l4= +golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI= +golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8= +golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842 h1:vr/HnozRka3pE4EsMEg1lgkXJkTFJCVUX+S/ZT6wYzM= +golang.org/x/exp v0.0.0-20240506185415-9bf2ced13842/go.mod h1:XtvwrStGgqGPLc4cjQfWqZHG1YFdYs6swckp8vpsjnc= +golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA= +golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac= +golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM= +golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= +golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y= +golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk= +golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg= +google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +modernc.org/gc/v3 v3.0.0-20240107210532-573471604cb6 h1:5D53IMaUuA5InSeMu9eJtlQXS2NxAhyWQvkKEgXZhHI= +modernc.org/gc/v3 v3.0.0-20240107210532-573471604cb6/go.mod h1:Qz0X07sNOR1jWYCrJMEnbW/X55x206Q7Vt4mz6/wHp4= +modernc.org/libc v1.50.9 h1:hIWf1uz55lorXQhfoEoezdUHjxzuO6ceshET/yWjSjk= +modernc.org/libc v1.50.9/go.mod h1:15P6ublJ9FJR8YQCGy8DeQ2Uwur7iW9Hserr/T3OFZE= +modernc.org/mathutil v1.6.0 h1:fRe9+AmYlaej+64JsEEhoWuAYBkOtQiMEU7n/XgfYi4= +modernc.org/mathutil v1.6.0/go.mod h1:Ui5Q9q1TR2gFm0AQRqQUaBWFLAhQpCwNcuhBOSedWPo= +modernc.org/memory v1.8.0 h1:IqGTL6eFMaDZZhEWwcREgeMXYwmW83LYW8cROZYkg+E= +modernc.org/memory v1.8.0/go.mod h1:XPZ936zp5OMKGWPqbD3JShgd/ZoQ7899TUuQqxY+peU= +modernc.org/sqlite v1.30.0 h1:8YhPUs/HTnlEgErn/jSYQTwHN/ex8CjHHjg+K9iG7LM= +modernc.org/sqlite v1.30.0/go.mod h1:cgkTARJ9ugeXSNaLBPK3CqbOe7Ec7ZhWPoMFGldEYEw= +modernc.org/strutil v1.2.0 h1:agBi9dp1I+eOnxXeiZawM8F4LawKv4NzGWSaLfyeNZA= +modernc.org/strutil v1.2.0/go.mod h1:/mdcBmfOibveCTBxUl5B5l6W+TTH1FXPLHZE6bTosX0= +modernc.org/token v1.1.0 h1:Xl7Ap9dKaEs5kLoOQeQmPWevfnk/DM5qcLcYlA8ys6Y= +modernc.org/token v1.1.0/go.mod h1:UGzOrNV1mAFSEB63lOFHIpNRUVMvYTc6yu1SMY/XTDM= diff --git a/go-runtime/ftl/testdata/go/time/ftl.toml b/go-runtime/ftl/testdata/go/time/ftl.toml new file mode 100644 index 0000000000..c7449d155e --- /dev/null +++ b/go-runtime/ftl/testdata/go/time/ftl.toml @@ -0,0 +1,5 @@ +module = "time" +language = "go" + +[go.replace] +"github.com/TBD54566975/ftl" = "../.." diff --git a/go-runtime/ftl/testdata/go/time/go.mod b/go-runtime/ftl/testdata/go/time/go.mod new file mode 100644 index 0000000000..406abdfc9a --- /dev/null +++ b/go-runtime/ftl/testdata/go/time/go.mod @@ -0,0 +1,5 @@ +module ftl/time + +go 1.22.2 + +replace github.com/TBD54566975/ftl => ./../../../../.. diff --git a/go-runtime/ftl/testdata/go/time/go.sum b/go-runtime/ftl/testdata/go/time/go.sum new file mode 100644 index 0000000000..e69de29bb2 diff --git a/go-runtime/ftl/testdata/go/time/time.go b/go-runtime/ftl/testdata/go/time/time.go new file mode 100644 index 0000000000..e18f7c0e26 --- /dev/null +++ b/go-runtime/ftl/testdata/go/time/time.go @@ -0,0 +1,18 @@ +package time + +import ( + "context" + "time" +) + +type TimeRequest struct{} +type TimeResponse struct { + Time time.Time +} + +// Time returns the current time. +// +//ftl:verb export +func Time(ctx context.Context, req TimeRequest) (TimeResponse, error) { + return TimeResponse{Time: time.Now()}, nil +} diff --git a/integration/testdata/schema-generate/go.mod b/go-runtime/ftl/testdata/schema-generate/go.mod similarity index 100% rename from integration/testdata/schema-generate/go.mod rename to go-runtime/ftl/testdata/schema-generate/go.mod diff --git a/integration/testdata/schema-generate/template.js b/go-runtime/ftl/testdata/schema-generate/template.js similarity index 100% rename from integration/testdata/schema-generate/template.js rename to go-runtime/ftl/testdata/schema-generate/template.js diff --git a/integration/testdata/schema-generate/test.txt b/go-runtime/ftl/testdata/schema-generate/test.txt similarity index 100% rename from integration/testdata/schema-generate/test.txt rename to go-runtime/ftl/testdata/schema-generate/test.txt diff --git a/integration/integration_test.go b/integration/integration_test.go deleted file mode 100644 index 69ceceaef3..0000000000 --- a/integration/integration_test.go +++ /dev/null @@ -1,296 +0,0 @@ -//go:build integration - -package integration_test - -import ( - "fmt" - "net/http" - "os" - "path/filepath" - "strings" - "testing" - "time" - - "connectrpc.com/connect" - "github.com/alecthomas/assert/v2" - "github.com/alecthomas/repr" - "golang.org/x/sync/errgroup" - - ftlv1 "github.com/TBD54566975/ftl/backend/protos/xyz/block/ftl/v1" - schemapb "github.com/TBD54566975/ftl/backend/protos/xyz/block/ftl/v1/schema" - . "github.com/TBD54566975/ftl/integration" -) - -func TestCron(t *testing.T) { - dir := t.TempDir() - // Due to some MacOS magic, /tmp differs between this test code and the - // executing module, so we need to pass the file path as an environment - // variable. - tmpFile := filepath.Join(dir, "cron.txt") - t.Setenv("DEST_FILE", tmpFile) - - t.Cleanup(func() { _ = os.Remove(tmpFile) }) - - Run(t, "", - CopyModule("cron"), - Deploy("cron"), - func(t testing.TB, ic TestContext) { - _, err := os.Stat(tmpFile) - assert.NoError(t, err) - }, - ) -} - -func TestLifecycle(t *testing.T) { - Run(t, "", - Exec("ftl", "init", "go", ".", "echo"), - Deploy("echo"), - Call("echo", "echo", Obj{"name": "Bob"}, func(t testing.TB, response Obj) { - assert.Equal(t, "Hello, Bob!", response["message"]) - }), - ) -} - -func TestInterModuleCall(t *testing.T) { - Run(t, "", - CopyModule("echo"), - CopyModule("time"), - Deploy("time"), - Deploy("echo"), - Call("echo", "echo", Obj{"name": "Bob"}, func(t testing.TB, response Obj) { - message, ok := response["message"].(string) - assert.True(t, ok, "message is not a string: %s", repr.String(response)) - if !strings.HasPrefix(message, "Hello, Bob!!! It is ") { - t.Fatalf("unexpected response: %q", response) - } - }), - ) -} - -func TestNonExportedDecls(t *testing.T) { - Run(t, "", - CopyModule("time"), - Deploy("time"), - CopyModule("echo"), - Deploy("echo"), - CopyModule("notexportedverb"), - ExpectError( - ExecWithOutput("ftl", "deploy", "notexportedverb"), - "call first argument must be a function but is an unresolved reference to echo.Echo, does it need to be exported?"), - ) -} - -func TestUndefinedExportedDecls(t *testing.T) { - Run(t, "", - CopyModule("time"), - Deploy("time"), - CopyModule("echo"), - Deploy("echo"), - CopyModule("undefinedverb"), - ExpectError( - ExecWithOutput("ftl", "deploy", "undefinedverb"), - "call first argument must be a function but is an unresolved reference to echo.Undefined"), - ) -} - -func TestDatabase(t *testing.T) { - Run(t, "database/ftl-project.toml", - // deploy real module against "testdb" - CopyModule("database"), - CreateDBAction("database", "testdb", false), - Deploy("database"), - Call("database", "insert", Obj{"data": "hello"}, nil), - QueryRow("testdb", "SELECT data FROM requests", "hello"), - - // run tests which should only affect "testdb_test" - CreateDBAction("database", "testdb", true), - ExecModuleTest("database"), - QueryRow("testdb", "SELECT data FROM requests", "hello"), - ) -} - -func TestSchemaGenerate(t *testing.T) { - Run(t, "", - CopyDir("../schema-generate", "schema-generate"), - Mkdir("build/schema-generate"), - Exec("ftl", "schema", "generate", "schema-generate", "build/schema-generate"), - FileContains("build/schema-generate/test.txt", "olleh"), - ) -} - -func TestHttpEncodeOmitempty(t *testing.T) { - Run(t, "", - CopyModule("omitempty"), - Deploy("omitempty"), - HttpCall(http.MethodGet, "/get", JsonData(t, Obj{}), func(t testing.TB, resp *HTTPResponse) { - assert.Equal(t, 200, resp.Status) - _, ok := resp.JsonBody["mustset"] - assert.True(t, ok) - _, ok = resp.JsonBody["error"] - assert.False(t, ok) - }), - ) -} - -func TestRuntimeReflection(t *testing.T) { - Run(t, "", - CopyModule("runtimereflection"), - ExecModuleTest("runtimereflection"), - ) -} - -func TestModuleUnitTests(t *testing.T) { - Run(t, "", - CopyModule("time"), - CopyModule("wrapped"), - CopyModule("verbtypes"), - Build("time", "wrapped", "verbtypes"), - ExecModuleTest("wrapped"), - ExecModuleTest("verbtypes"), - ) -} - -func TestLease(t *testing.T) { - Run(t, "", - CopyModule("leases"), - Build("leases"), - // checks if leases work in a unit test environment - ExecModuleTest("leases"), - Deploy("leases"), - // checks if it leases work with a real controller - func(t testing.TB, ic TestContext) { - // Start a lease. - wg := errgroup.Group{} - wg.Go(func() error { - Infof("Acquiring lease") - resp, err := ic.Verbs.Call(ic, connect.NewRequest(&ftlv1.CallRequest{ - Verb: &schemapb.Ref{Module: "leases", Name: "acquire"}, - Body: []byte("{}"), - })) - if respErr := resp.Msg.GetError(); respErr != nil { - return fmt.Errorf("received error on first call: %v", respErr) - } - return err - }) - - time.Sleep(time.Second) - - Infof("Trying to acquire lease again") - // Trying to obtain the lease again should fail. - resp, err := ic.Verbs.Call(ic, connect.NewRequest(&ftlv1.CallRequest{ - Verb: &schemapb.Ref{Module: "leases", Name: "acquire"}, - Body: []byte("{}"), - })) - assert.NoError(t, err) - if resp.Msg.GetError() == nil || !strings.Contains(resp.Msg.GetError().Message, "could not acquire lease") { - t.Fatalf("expected error but got: %#v", resp.Msg.GetError()) - } - err = wg.Wait() - assert.NoError(t, err) - }, - ) -} - -func TestFSMGoTests(t *testing.T) { - logFilePath := filepath.Join(t.TempDir(), "fsm.log") - t.Setenv("FSM_LOG_FILE", logFilePath) - Run(t, "", - CopyModule("fsm"), - Build("fsm"), - ExecModuleTest("fsm"), - ) -} - -func TestFSM(t *testing.T) { - logFilePath := filepath.Join(t.TempDir(), "fsm.log") - t.Setenv("FSM_LOG_FILE", logFilePath) - fsmInState := func(instance, status, state string) Action { - return QueryRow("ftl", fmt.Sprintf(` - SELECT status, current_state - FROM fsm_instances - WHERE fsm = 'fsm.fsm' AND key = '%s' - `, instance), status, state) - } - Run(t, "", - CopyModule("fsm"), - Deploy("fsm"), - - Call("fsm", "sendOne", Obj{"instance": "1"}, nil), - Call("fsm", "sendOne", Obj{"instance": "2"}, nil), - FileContains(logFilePath, "start 1"), - FileContains(logFilePath, "start 2"), - fsmInState("1", "running", "fsm.start"), - fsmInState("2", "running", "fsm.start"), - - Call("fsm", "sendOne", Obj{"instance": "1"}, nil), - FileContains(logFilePath, "middle 1"), - fsmInState("1", "running", "fsm.middle"), - - Call("fsm", "sendOne", Obj{"instance": "1"}, nil), - FileContains(logFilePath, "end 1"), - fsmInState("1", "completed", "fsm.end"), - - Fail(Call("fsm", "sendOne", Obj{"instance": "1"}, nil), - "FSM instance 1 is already in state fsm.end"), - - // Invalid state transition - Fail(Call("fsm", "sendTwo", Obj{"instance": "2"}, nil), - "invalid state transition"), - - Call("fsm", "sendOne", Obj{"instance": "2"}, nil), - FileContains(logFilePath, "middle 2"), - fsmInState("2", "running", "fsm.middle"), - - // Invalid state transition - Fail(Call("fsm", "sendTwo", Obj{"instance": "2"}, nil), - "invalid state transition"), - ) -} - -func TestFSMRetry(t *testing.T) { - checkRetries := func(origin, verb string, delays []time.Duration) Action { - return func(t testing.TB, ic TestContext) { - results := []any{} - for i := 0; i < len(delays); i++ { - values := GetRow(t, ic, "ftl", fmt.Sprintf("SELECT scheduled_at FROM async_calls WHERE origin = '%s' AND verb = '%s' AND state = 'error' ORDER BY created_at LIMIT 1 OFFSET %d", origin, verb, i), 1) - results = append(results, values[0]) - } - times := []time.Time{} - for i, r := range results { - ts, ok := r.(time.Time) - assert.True(t, ok, "unexpected time value: %v", r) - times = append(times, ts) - if i > 0 { - delay := times[i].Sub(times[i-1]) - targetDelay := delays[i-1] - assert.True(t, delay >= targetDelay && delay < time.Second+targetDelay, "unexpected time diff for %s retry %d: %v (expected %v - %v)", origin, i, delay, targetDelay, time.Second+targetDelay) - } - } - } - } - - Run(t, "", - CopyModule("fsmretry"), - Build("fsmretry"), - Deploy("fsmretry"), - // start 2 FSM instances - Call("fsmretry", "start", Obj{"id": "1"}, func(t testing.TB, response Obj) {}), - Call("fsmretry", "start", Obj{"id": "2"}, func(t testing.TB, response Obj) {}), - - Sleep(2*time.Second), - - // transition the FSM, should fail each time. - Call("fsmretry", "startTransitionToTwo", Obj{"id": "1"}, func(t testing.TB, response Obj) {}), - Call("fsmretry", "startTransitionToThree", Obj{"id": "2"}, func(t testing.TB, response Obj) {}), - - Sleep(8*time.Second), //6s is longest run of retries - - // both FSMs instances should have failed - QueryRow("ftl", "SELECT COUNT(*) FROM fsm_instances WHERE status = 'failed'", int64(2)), - - QueryRow("ftl", fmt.Sprintf("SELECT COUNT(*) FROM async_calls WHERE origin = '%s' AND verb = '%s'", "fsm:fsmretry.fsm:1", "fsmretry.state2"), int64(4)), - checkRetries("fsm:fsmretry.fsm:1", "fsmretry.state2", []time.Duration{time.Second, time.Second, time.Second}), - QueryRow("ftl", fmt.Sprintf("SELECT COUNT(*) FROM async_calls WHERE origin = '%s' AND verb = '%s'", "fsm:fsmretry.fsm:2", "fsmretry.state3"), int64(4)), - checkRetries("fsm:fsmretry.fsm:2", "fsmretry.state3", []time.Duration{time.Second, 2 * time.Second, 3 * time.Second}), - ) -} diff --git a/integration/testdata/go/time/go.mod b/integration/testdata/go/time/go.mod deleted file mode 100644 index 6c51df80ff..0000000000 --- a/integration/testdata/go/time/go.mod +++ /dev/null @@ -1,5 +0,0 @@ -module ftl/time - -go 1.22.2 - -replace github.com/TBD54566975/ftl => ../../../..