Skip to content

Commit

Permalink
fix: just tidy works with fuzz test (#2204)
Browse files Browse the repository at this point in the history
  • Loading branch information
worstell authored Jul 31, 2024
1 parent cd2b4fa commit 532a48d
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 201 deletions.
34 changes: 28 additions & 6 deletions go-runtime/schema/schema_fuzz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@ package schema

import (
"bytes"
"context"
"fmt"
"os"
"path/filepath"
"strings"
"testing"
"text/template"

"github.com/otiai10/copy"

"github.com/TBD54566975/ftl/backend/schema"
"github.com/TBD54566975/ftl/internal"
"github.com/TBD54566975/ftl/internal/exec"
"github.com/TBD54566975/ftl/internal/log"
"github.com/alecthomas/assert/v2"
)

Expand Down Expand Up @@ -240,18 +246,34 @@ func FuzzExtract(f *testing.F) {
}
typenames := generateSymbolTypeStrings(allSymbols)

tmpDir, err := os.MkdirTemp("", "fuzz_test")
assert.NoError(f, err)
defer os.RemoveAll(tmpDir)

err = copy.Copy("testdata/fuzz", tmpDir)
assert.NoError(f, err)

first := true
f.Fuzz(func(t *testing.T, symbolType string) {
code := generateSourceCode(symbolType)

moduleDir := "testdata/test"
abs, err := filepath.Abs(moduleDir)
assert.NoError(t, err)
filePath := filepath.Join(abs, "test.go")
filePath := filepath.Join(tmpDir, "fuzz.go")
err = os.WriteFile(filePath, []byte(code), 0600)
assert.NoError(t, err)
defer os.Remove(abs)

r, err := Extract(abs)
if first {
ctx := log.ContextWithNewDefaultLogger(context.Background())
rootDir, ok := internal.GitRoot("").Get()
assert.True(f, ok)
err = exec.Command(ctx, log.Debug, tmpDir, "go", "mod", "edit", "-replace", "github.com/TBD54566975/ftl="+rootDir).RunBuffered(ctx)
assert.NoError(f, err, "go mod edit failed")
err = exec.Command(ctx, log.Debug, tmpDir, "go", "mod", "tidy").RunBuffered(ctx)
assert.NoError(t, err, "go mod tidy failed")
// don't run this for all the permutations
first = false
}

r, err := Extract(tmpDir)
assert.NoError(t, err)
expected := tmpl(symbolType, typenames[symbolType])

Expand Down
File renamed without changes.
3 changes: 3 additions & 0 deletions go-runtime/schema/testdata/fuzz/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module ftl/test

go 1.22.2
Empty file.
47 changes: 0 additions & 47 deletions go-runtime/schema/testdata/test/go.mod

This file was deleted.

148 changes: 0 additions & 148 deletions go-runtime/schema/testdata/test/go.sum

This file was deleted.

0 comments on commit 532a48d

Please sign in to comment.