Skip to content

Commit

Permalink
fix(integration): create a new test dir per language
Browse files Browse the repository at this point in the history
Fixes #2412
  • Loading branch information
alecthomas committed Aug 17, 2024
1 parent a7bc9b3 commit a81d824
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
run: docker compose up -d --wait
- name: Test
run: |
go-test-annotate ${{ (github.event_name == 'pull_request' && github.event.action != 'enqueued') && '-short' || '' }}
go-test-annotate ${{ (github.event_name == 'pull_request' && github.event.action != 'enqueued' && !contains( github.event.pull_request.labels.*.name, 'run-integration')) && '-short' || '' }}
test-readme:
name: Test README
runs-on: ubuntu-latest
Expand Down
57 changes: 31 additions & 26 deletions internal/integration/harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,38 +138,12 @@ func run(t *testing.T, actionsOrOptions ...ActionOrOption) {
t.Setenv(key, value)
}

tmpDir := t.TempDir()

cwd, err := os.Getwd()
assert.NoError(t, err)

rootDir, ok := internal.GitRoot("").Get()
assert.True(t, ok)

if opts.ftlConfigPath != "" {
// TODO: We shouldn't be copying the shared config from the "go" testdata...
opts.ftlConfigPath = filepath.Join(cwd, "testdata", "go", opts.ftlConfigPath)
projectPath := filepath.Join(tmpDir, "ftl-project.toml")

// Copy the specified FTL config to the temporary directory.
err = copy.Copy(opts.ftlConfigPath, projectPath)
if err == nil {
t.Setenv("FTL_CONFIG", projectPath)
} else {
// Use a path into the testdata directory instead of one relative to
// tmpDir. Otherwise we have a chicken and egg situation where the config
// can't be loaded until the module is copied over, and the config itself
// is used by FTL during startup.
// Some tests still rely on this behavior, so we can't remove it entirely.
t.Logf("Failed to copy %s to %s: %s", opts.ftlConfigPath, projectPath, err)
t.Setenv("FTL_CONFIG", opts.ftlConfigPath)
}

} else {
err = os.WriteFile(filepath.Join(tmpDir, "ftl-project.toml"), []byte(`name = "integration"`), 0644)
assert.NoError(t, err)
}

// Build FTL binary
logger := log.Configure(&logWriter{logger: t}, log.Config{Level: log.Debug})
ctx := log.ContextWithLogger(context.Background(), logger)
Expand All @@ -188,6 +162,8 @@ func run(t *testing.T, actionsOrOptions ...ActionOrOption) {
for _, language := range opts.languages {
ctx, done := context.WithCancel(ctx)
t.Run(language, func(t *testing.T) {
tmpDir := initWorkDir(t, cwd, opts)

verbs := rpc.Dial(ftlv1connect.NewVerbServiceClient, "http://localhost:8892", log.Debug)

var controller ftlv1connect.ControllerServiceClient
Expand Down Expand Up @@ -232,6 +208,35 @@ func run(t *testing.T, actionsOrOptions ...ActionOrOption) {
}
}

func initWorkDir(t testing.TB, cwd string, opts options) string {
tmpDir := t.TempDir()

if opts.ftlConfigPath != "" {
// TODO: We shouldn't be copying the shared config from the "go" testdata...
opts.ftlConfigPath = filepath.Join(cwd, "testdata", "go", opts.ftlConfigPath)
projectPath := filepath.Join(tmpDir, "ftl-project.toml")

// Copy the specified FTL config to the temporary directory.
err := copy.Copy(opts.ftlConfigPath, projectPath)
if err == nil {
t.Setenv("FTL_CONFIG", projectPath)
} else {
// Use a path into the testdata directory instead of one relative to
// tmpDir. Otherwise we have a chicken and egg situation where the config
// can't be loaded until the module is copied over, and the config itself
// is used by FTL during startup.
// Some tests still rely on this behavior, so we can't remove it entirely.
t.Logf("Failed to copy %s to %s: %s", opts.ftlConfigPath, projectPath, err)
t.Setenv("FTL_CONFIG", opts.ftlConfigPath)
}

} else {
err := os.WriteFile(filepath.Join(tmpDir, "ftl-project.toml"), []byte(`name = "integration"`), 0644)
assert.NoError(t, err)
}
return tmpDir
}

type TestContext struct {
context.Context
// Temporary directory the test is executing in.
Expand Down
1 change: 0 additions & 1 deletion jvm-runtime/jvm_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ func TestLifecycle(t *testing.T) {
in.WithLanguages("java", "kotlin"),
in.GitInit(),
in.Exec("rm", "ftl-project.toml"),
in.IfLanguage("kotlin", in.Exec("rm", "-r", "echo")), //horrible, but we need to do cleanup, I wonder if we should be running each test in a separate directory
in.Exec("ftl", "init", "test", "."),
in.IfLanguage("java", in.Exec("ftl", "new", "java", ".", "echo")),
in.IfLanguage("kotlin", in.Exec("ftl", "new", "kotlin", ".", "echo")),
Expand Down

0 comments on commit a81d824

Please sign in to comment.