From c22d92c2da0c144d363cfb57b56d9e6c0a9606e9 Mon Sep 17 00:00:00 2001 From: Juho Makinen Date: Mon, 26 Aug 2024 15:52:02 +1000 Subject: [PATCH] chore: migrate deploy_test to integration tests in buildengine This tests the same things as the old test, but through slightly higher abstraction layer (cli instead of calling build engine functions directly) --- .../buildengine/deploy_integration_test.go | 23 +++++ internal/buildengine/deploy_test.go | 95 ------------------- internal/integration/harness.go | 17 +++- 3 files changed, 39 insertions(+), 96 deletions(-) create mode 100644 internal/buildengine/deploy_integration_test.go delete mode 100644 internal/buildengine/deploy_test.go diff --git a/internal/buildengine/deploy_integration_test.go b/internal/buildengine/deploy_integration_test.go new file mode 100644 index 0000000000..be83299e8c --- /dev/null +++ b/internal/buildengine/deploy_integration_test.go @@ -0,0 +1,23 @@ +//go:build integration + +package buildengine + +import ( + "testing" + + in "github.com/TBD54566975/ftl/internal/integration" +) + +func TestDeploy(t *testing.T) { + in.Run(t, + in.WithTestDataDir("testdata"), + in.CopyModule("another"), + + // Build first to make sure the files are there. + in.Build("another"), + in.FileExists("/another/.ftl/main"), + + // Test that the deployment works and starts correctly + in.Deploy("another"), + ) +} diff --git a/internal/buildengine/deploy_test.go b/internal/buildengine/deploy_test.go deleted file mode 100644 index df6e7e37f9..0000000000 --- a/internal/buildengine/deploy_test.go +++ /dev/null @@ -1,95 +0,0 @@ -package buildengine - -import ( - "context" - "os" - "testing" - - "connectrpc.com/connect" - "github.com/alecthomas/assert/v2" - - ftlv1 "github.com/TBD54566975/ftl/backend/protos/xyz/block/ftl/v1" - "github.com/TBD54566975/ftl/backend/schema" - "github.com/TBD54566975/ftl/internal/log" - "github.com/TBD54566975/ftl/internal/moduleconfig" - "github.com/TBD54566975/ftl/internal/sha256" -) - -type mockDeployClient struct { - MissingDigests []string - DeploymentKey string -} - -func (m *mockDeployClient) GetArtefactDiffs(context.Context, *connect.Request[ftlv1.GetArtefactDiffsRequest]) (*connect.Response[ftlv1.GetArtefactDiffsResponse], error) { - return connect.NewResponse(&ftlv1.GetArtefactDiffsResponse{ - MissingDigests: m.MissingDigests, - }), nil -} - -func (m *mockDeployClient) UploadArtefact(ctx context.Context, req *connect.Request[ftlv1.UploadArtefactRequest]) (*connect.Response[ftlv1.UploadArtefactResponse], error) { - sha256digest := sha256.Sum(req.Msg.Content) - return connect.NewResponse(&ftlv1.UploadArtefactResponse{Digest: sha256digest[:]}), nil -} - -func (m *mockDeployClient) CreateDeployment(context.Context, *connect.Request[ftlv1.CreateDeploymentRequest]) (*connect.Response[ftlv1.CreateDeploymentResponse], error) { - return connect.NewResponse(&ftlv1.CreateDeploymentResponse{DeploymentKey: m.DeploymentKey}), nil -} - -func (m *mockDeployClient) ReplaceDeploy(context.Context, *connect.Request[ftlv1.ReplaceDeployRequest]) (*connect.Response[ftlv1.ReplaceDeployResponse], error) { - return nil, nil -} - -func (m *mockDeployClient) Status(context.Context, *connect.Request[ftlv1.StatusRequest]) (*connect.Response[ftlv1.StatusResponse], error) { - resp := &ftlv1.StatusResponse{ - Deployments: []*ftlv1.StatusResponse_Deployment{ - {Key: m.DeploymentKey, Replicas: 1}, - }, - } - return connect.NewResponse(resp), nil -} - -func TestDeploy(t *testing.T) { - if testing.Short() { - t.SkipNow() - } - sch := &schema.Schema{ - Modules: []*schema.Module{ - schema.Builtins(), - {Name: "another", Decls: []schema.Decl{ - &schema.Data{Name: "EchoRequest"}, - &schema.Data{Name: "EchoResponse"}, - &schema.Verb{ - Name: "echo", - Request: &schema.Ref{Name: "EchoRequest"}, - Response: &schema.Ref{Name: "EchoResponse"}, - }, - }}, - }, - } - ctx := log.ContextWithLogger(context.Background(), log.Configure(os.Stderr, log.Config{})) - - modulePath := "testdata/another" - module, err := LoadModule(modulePath) - assert.NoError(t, err) - - projectRootDir := t.TempDir() - - // generate stubs to create the shared modules directory - err = GenerateStubs(ctx, projectRootDir, sch.Modules, []moduleconfig.ModuleConfig{module.Config}) - assert.NoError(t, err) - - // Build first to make sure the files are there. - err = Build(ctx, projectRootDir, sch, module, &mockModifyFilesTransaction{}) - assert.NoError(t, err) - - sum, err := sha256.SumFile(modulePath + "/.ftl/main") - assert.NoError(t, err) - - client := &mockDeployClient{ - MissingDigests: []string{sum.String()}, - DeploymentKey: "test-deployment", - } - - err = Deploy(ctx, module, int32(1), true, client) - assert.NoError(t, err) -} diff --git a/internal/integration/harness.go b/internal/integration/harness.go index 0dd23b7793..af379d8348 100644 --- a/internal/integration/harness.go +++ b/internal/integration/harness.go @@ -59,6 +59,15 @@ func WithLanguages(languages ...string) Option { } } +// WithTestDataDir sets the directory from which to look for test data. +// +// Defaults to "testdata/" if not provided. +func WithTestDataDir(dir string) Option { + return func(o *options) { + o.testDataDir = dir + } +} + // WithFTLConfig is a Run* option that specifies the FTL config to use. // // This will set FTL_CONFIG for this test, then pass in the relative @@ -97,6 +106,7 @@ func WithoutController() Option { type options struct { languages []string + testDataDir string ftlConfigPath string startController bool requireJava bool @@ -176,10 +186,15 @@ func run(t *testing.T, actionsOrOptions ...ActionOrOption) { ctx = startProcess(ctx, t, filepath.Join(binDir, "ftl"), "serve", "--recreate") } + testData := filepath.Join(cwd, "testdata", language) + if opts.testDataDir != "" { + testData = opts.testDataDir + } + ic := TestContext{ Context: ctx, RootDir: rootDir, - testData: filepath.Join(cwd, "testdata", language), + testData: testData, workDir: tmpDir, binDir: binDir, Verbs: verbs,