Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
matt2e committed Mar 20, 2024
1 parent 35139bb commit e93928e
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 60 deletions.
5 changes: 3 additions & 2 deletions buildengine/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package buildengine

import (
"context"
"github.com/alecthomas/assert/v2"
"os"
"path/filepath"
"testing"

"github.com/alecthomas/assert/v2"

"github.com/TBD54566975/ftl/backend/schema"
"github.com/TBD54566975/ftl/internal/log"
)
Expand All @@ -26,7 +27,7 @@ func testBuild(
) {
t.Helper()
ctx := log.ContextWithLogger(context.Background(), log.Configure(os.Stderr, log.Config{}))
module, err := LoadModule(ctx, bctx.moduleDir)
module, err := LoadModule(bctx.moduleDir)
assert.NoError(t, err)

err = Build(ctx, bctx.sch, module)
Expand Down
2 changes: 1 addition & 1 deletion buildengine/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func TestDeploy(t *testing.T) {
ctx := log.ContextWithLogger(context.Background(), log.Configure(os.Stderr, log.Config{}))

modulePath := "testdata/modules/another"
module, err := LoadModule(ctx, modulePath)
module, err := LoadModule(modulePath)
assert.NoError(t, err)

// Build first to make sure the files are there.
Expand Down
4 changes: 2 additions & 2 deletions buildengine/deps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import (
func TestExtractDepsGo(t *testing.T) {
deps, err := extractGoFTLImports("test", "testdata/modules/alpha")
assert.NoError(t, err)
assert.Equal(t, []string{"another", "other"}, deps)
assert.Equal(t, []ProjectKey{"another", "other"}, deps)
}

func TestExtractDepsKotlin(t *testing.T) {
deps, err := extractKotlinFTLImports("test", "testdata/modules/alphakotlin")
assert.NoError(t, err)
assert.Equal(t, []string{"builtin", "other"}, deps)
assert.Equal(t, []ProjectKey{"builtin", "other"}, deps)
}
94 changes: 51 additions & 43 deletions buildengine/discover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,58 +12,66 @@ import (

func TestDiscoverModules(t *testing.T) {
ctx := log.ContextWithNewDefaultLogger(context.Background())
modules, err := DiscoverModules(ctx, "testdata/modules")
modules, err := discoverModules(ctx, "testdata/modules")
assert.NoError(t, err)
expected := []moduleconfig.ModuleConfig{
expected := []Module{
{
Dir: "testdata/modules/alpha",
Language: "go",
Realm: "home",
Module: "alpha",
Deploy: []string{"main"},
DeployDir: "_ftl",
Schema: "schema.pb",
Watch: []string{"**/*.go", "go.mod", "go.sum"},
ModuleConfig: moduleconfig.ModuleConfig{
Dir: "testdata/modules/alpha",
Language: "go",
Realm: "home",
Module: "alpha",
Deploy: []string{"main"},
DeployDir: "_ftl",
Schema: "schema.pb",
Watch: []string{"**/*.go", "go.mod", "go.sum"},
},
},
{
Dir: "testdata/modules/another",
Language: "go",
Realm: "home",
Module: "another",
Deploy: []string{"main"},
DeployDir: "_ftl",
Schema: "schema.pb",
Watch: []string{"**/*.go", "go.mod", "go.sum"},
ModuleConfig: moduleconfig.ModuleConfig{
Dir: "testdata/modules/another",
Language: "go",
Realm: "home",
Module: "another",
Deploy: []string{"main"},
DeployDir: "_ftl",
Schema: "schema.pb",
Watch: []string{"**/*.go", "go.mod", "go.sum"},
},
},
{
Dir: "testdata/modules/echokotlin",
Language: "kotlin",
Realm: "home",
Module: "echo",
Build: "mvn -B compile",
Deploy: []string{
"main",
"classes",
"dependency",
"classpath.txt",
},
DeployDir: "target",
Schema: "schema.pb",
Watch: []string{
"pom.xml",
"src/**",
"target/generated-sources",
ModuleConfig: moduleconfig.ModuleConfig{
Dir: "testdata/modules/echokotlin",
Language: "kotlin",
Realm: "home",
Module: "echo",
Build: "mvn -B compile",
Deploy: []string{
"main",
"classes",
"dependency",
"classpath.txt",
},
DeployDir: "target",
Schema: "schema.pb",
Watch: []string{
"pom.xml",
"src/**",
"target/generated-sources",
},
},
},
{
Dir: "testdata/modules/other",
Language: "go",
Realm: "home",
Module: "other",
Deploy: []string{"main"},
DeployDir: "_ftl",
Schema: "schema.pb",
Watch: []string{"**/*.go", "go.mod", "go.sum"},
ModuleConfig: moduleconfig.ModuleConfig{
Dir: "testdata/modules/other",
Language: "go",
Realm: "home",
Module: "other",
Deploy: []string{"main"},
DeployDir: "_ftl",
Schema: "schema.pb",
Watch: []string{"**/*.go", "go.mod", "go.sum"},
},
},
}
assert.Equal(t, expected, modules)
Expand Down
9 changes: 5 additions & 4 deletions buildengine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ func (e *Engine) watchForModuleChanges(ctx context.Context, period time.Duration
config := event.Project.Config()
err := e.buildAndDeploy(ctx, 1, true, config.Key)
if err != nil {
logger.Errorf(err, "build and deploy failed for %v: %w", event.Project, err)
logger.Errorf(err, "build and deploy failed for %v: %v", event.Project, err)
}
}
case change := <-schemaChanges:
Expand Down Expand Up @@ -536,10 +536,11 @@ func (e *Engine) gatherSchemas(
out[dep] = moduleSchemas[dep]
if dep != "builtin" {
depModule, ok := e.projects[dep]
if !ok {
return fmt.Errorf("dependency %q not found", dep)
// TODO: should we be gathering schemas from dependencies without a project?
// This can happen if the schema is loaded from the controller
if ok {
e.gatherSchemas(moduleSchemas, depModule, out)

Check failure on line 542 in buildengine/engine.go

View workflow job for this annotation

GitHub Actions / Lint

Error return value of `e.gatherSchemas` is not checked (errcheck)
}
e.gatherSchemas(moduleSchemas, depModule, out)
}
}
return nil
Expand Down
4 changes: 2 additions & 2 deletions buildengine/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (

func TestEngine(t *testing.T) {
ctx := log.ContextWithNewDefaultLogger(context.Background())
engine, err := buildengine.New(ctx, nil, []string{"testdata/modules/alpha", "testdata/modules/another"})
engine, err := buildengine.New(ctx, nil, []string{"testdata/modules/alpha", "testdata/modules/another"}, nil)
assert.NoError(t, err)

defer engine.Close()
Expand Down Expand Up @@ -43,7 +43,7 @@ func TestEngine(t *testing.T) {
}
engine.Import(ctx, otherSchema)

expected := map[string][]string{
expected := map[buildengine.ProjectKey][]buildengine.ProjectKey{
"alpha": {"another", "other", "builtin"},
"another": {"builtin"},
"other": {},
Expand Down
4 changes: 2 additions & 2 deletions buildengine/topological_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import (
)

func TestTopologicalSort(t *testing.T) {
graph := map[string][]string{
graph := map[ProjectKey][]ProjectKey{
"alpha": {"beta", "gamma"},
"beta": {"kappa"},
"gamma": {"kappa"},
"kappa": {},
"delta": {},
}
topo := TopologicalSort(graph)
expected := [][]string{
expected := [][]ProjectKey{
{"delta", "kappa"},
{"beta", "gamma"},
{"alpha"},
Expand Down
8 changes: 4 additions & 4 deletions buildengine/watch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestWatch(t *testing.T) {

// Start the watch
events := make(chan WatchEvent, 128)
watch := Watch(ctx, time.Millisecond*500, dir)
watch := Watch(ctx, time.Millisecond*500, []string{dir}, nil)
watch.Subscribe(events)

// Initiate a bunch of changes.
Expand Down Expand Up @@ -58,17 +58,17 @@ func TestWatch(t *testing.T) {
for _, event := range allEvents {
switch event := event.(type) {
case WatchEventProjectAdded:
if event.Project.Module == "one" || event.Project.Module == "two" {
if event.Project.Config().Key == "one" || event.Project.Config().Key == "two" {
found++
}

case WatchEventProjectRemoved:
if event.Project.Module == "two" {
if event.Project.Config().Key == "two" {
found++
}

case WatchEventProjectChanged:
if event.Project.Module == "one" {
if event.Project.Config().Key == "one" {
found++
}
}
Expand Down

0 comments on commit e93928e

Please sign in to comment.