diff --git a/internal/buildengine/build_go_test.go b/internal/buildengine/build_go_test.go index 8f324379c6..5515ed3ac6 100644 --- a/internal/buildengine/build_go_test.go +++ b/internal/buildengine/build_go_test.go @@ -3,11 +3,14 @@ package buildengine import ( "fmt" "os" + "path/filepath" "runtime" "testing" "github.com/alecthomas/assert/v2" + "github.com/otiai10/copy" + "github.com/TBD54566975/ftl/backend/schema" ) @@ -51,6 +54,16 @@ func TestGoModVersion(t *testing.T) { if testing.Short() { t.SkipNow() } + tmpDir, err := os.MkdirTemp("", "testdata_build") + assert.NoError(t, err) + defer os.RemoveAll(tmpDir) + + err = copy.Copy(filepath.Join("testdata", "highgoversion"), tmpDir) + assert.NoError(t, err) + + // This file causes constant IDE errors, we can't actually have broken go.mod files in the tree + os.Rename(filepath.Join(tmpDir, "go.mod.ignore"), filepath.Join(tmpDir, "go.mod")) + sch := &schema.Schema{ Modules: []*schema.Module{ schema.Builtins(), @@ -66,7 +79,7 @@ func TestGoModVersion(t *testing.T) { }, } bctx := buildContext{ - moduleDir: "testdata/highgoversion", + moduleDir: tmpDir, buildDir: ".ftl", sch: sch, } diff --git a/internal/buildengine/discover_test.go b/internal/buildengine/discover_test.go index d8c1377b65..7552a1621b 100644 --- a/internal/buildengine/discover_test.go +++ b/internal/buildengine/discover_test.go @@ -2,22 +2,38 @@ package buildengine import ( "context" + "os" + "path/filepath" "testing" "github.com/alecthomas/assert/v2" + "github.com/otiai10/copy" + "github.com/TBD54566975/ftl/internal/log" "github.com/TBD54566975/ftl/internal/moduleconfig" ) func TestDiscoverModules(t *testing.T) { ctx := log.ContextWithNewDefaultLogger(context.Background()) - modules, err := DiscoverModules(ctx, []string{"testdata"}) + + tmpDir, err := os.MkdirTemp("", "testdata_discover") + assert.NoError(t, err) + defer os.RemoveAll(tmpDir) + + err = copy.Copy("testdata", tmpDir) + assert.NoError(t, err) + + // This file causes constant IDE errors, we can't actually have broken go.mod files in the tree + err = os.Rename(filepath.Join(tmpDir, "highgoversion", "go.mod.ignore"), filepath.Join(tmpDir, "highgoversion", "go.mod")) + assert.NoError(t, err) + + modules, err := DiscoverModules(ctx, []string{tmpDir}) assert.NoError(t, err) expected := []Module{ { Config: moduleconfig.ModuleConfig{ - Dir: "testdata/alpha", + Dir: filepath.Join(tmpDir, "alpha"), Language: "go", Realm: "home", Module: "alpha", @@ -30,7 +46,7 @@ func TestDiscoverModules(t *testing.T) { }, { Config: moduleconfig.ModuleConfig{ - Dir: "testdata/another", + Dir: filepath.Join(tmpDir, "another"), Language: "go", Realm: "home", Module: "another", @@ -43,7 +59,7 @@ func TestDiscoverModules(t *testing.T) { }, { Config: moduleconfig.ModuleConfig{ - Dir: "testdata/depcycle1", + Dir: filepath.Join(tmpDir, "depcycle1"), Language: "go", Realm: "home", Module: "depcycle1", @@ -56,7 +72,7 @@ func TestDiscoverModules(t *testing.T) { }, { Config: moduleconfig.ModuleConfig{ - Dir: "testdata/depcycle2", + Dir: filepath.Join(tmpDir, "depcycle2"), Language: "go", Realm: "home", Module: "depcycle2", @@ -69,7 +85,7 @@ func TestDiscoverModules(t *testing.T) { }, { Config: moduleconfig.ModuleConfig{ - Dir: "testdata/echokotlin", + Dir: filepath.Join(tmpDir, "echokotlin"), Language: "kotlin", Realm: "home", Module: "echo", @@ -94,7 +110,7 @@ func TestDiscoverModules(t *testing.T) { }, { Config: moduleconfig.ModuleConfig{ - Dir: "testdata/external", + Dir: filepath.Join(tmpDir, "external"), Language: "go", Realm: "home", Module: "external", @@ -114,7 +130,7 @@ func TestDiscoverModules(t *testing.T) { }, { Config: moduleconfig.ModuleConfig{ - Dir: "testdata/externalkotlin", + Dir: filepath.Join(tmpDir, "externalkotlin"), Language: "kotlin", Realm: "home", Module: "externalkotlin", @@ -139,7 +155,7 @@ func TestDiscoverModules(t *testing.T) { }, { Config: moduleconfig.ModuleConfig{ - Dir: "testdata/highgoversion", + Dir: filepath.Join(tmpDir, "highgoversion"), Language: "go", Realm: "home", Module: "highgoversion", @@ -152,7 +168,7 @@ func TestDiscoverModules(t *testing.T) { }, { Config: moduleconfig.ModuleConfig{ - Dir: "testdata/integer", + Dir: filepath.Join(tmpDir, "integer"), Language: "go", Realm: "home", Module: "integer", @@ -165,7 +181,7 @@ func TestDiscoverModules(t *testing.T) { }, { Config: moduleconfig.ModuleConfig{ - Dir: "testdata/other", + Dir: filepath.Join(tmpDir, "other"), Language: "go", Realm: "home", Module: "other", diff --git a/internal/buildengine/testdata/highgoversion/go.mod b/internal/buildengine/testdata/highgoversion/go.mod.ignore similarity index 96% rename from internal/buildengine/testdata/highgoversion/go.mod rename to internal/buildengine/testdata/highgoversion/go.mod.ignore index f8f5d9d31b..3a8da338d2 100644 --- a/internal/buildengine/testdata/highgoversion/go.mod +++ b/internal/buildengine/testdata/highgoversion/go.mod.ignore @@ -1,5 +1,7 @@ module ftl/highgoversion +// This file causes intellij errors if it is just called go.mod + go 9000.1.1 require github.com/TBD54566975/ftl v0.177.1