Skip to content

Commit

Permalink
chore: fix intellij errors
Browse files Browse the repository at this point in the history
Having a go.mod file with a broken version makes Intellij throw constant errors.

This fixes is by changing the name and renaming it back in a temp directory as part of the test.
  • Loading branch information
stuartwdouglas committed Aug 23, 2024
1 parent b20986b commit 1ca8118
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 12 deletions.
15 changes: 14 additions & 1 deletion internal/buildengine/build_go_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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"))

Check failure on line 65 in internal/buildengine/build_go_test.go

View workflow job for this annotation

GitHub Actions / Lint

Error return value of `os.Rename` is not checked (errcheck)

sch := &schema.Schema{
Modules: []*schema.Module{
schema.Builtins(),
Expand All @@ -66,7 +79,7 @@ func TestGoModVersion(t *testing.T) {
},
}
bctx := buildContext{
moduleDir: "testdata/highgoversion",
moduleDir: tmpDir,
buildDir: ".ftl",
sch: sch,
}
Expand Down
38 changes: 27 additions & 11 deletions internal/buildengine/discover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 1ca8118

Please sign in to comment.