Skip to content

Commit

Permalink
chore: relocate console service and add integration tests (#2199)
Browse files Browse the repository at this point in the history
- Adds `ConsoleService` to integration testcontext
- Adds a test for `GetModules` to help catch errors that will cause the
console to not load.

In a future refactor, we will fix the console to not fail from just a
single call like this.
  • Loading branch information
wesbillman authored Jul 30, 2024
1 parent 0777796 commit 78f3a13
Show file tree
Hide file tree
Showing 10 changed files with 273 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package controller
package console

import (
"context"
Expand Down Expand Up @@ -30,7 +30,7 @@ type ConsoleService struct {

var _ pbconsoleconnect.ConsoleServiceHandler = (*ConsoleService)(nil)

func NewConsoleService(dal *dal.DAL) *ConsoleService {
func NewService(dal *dal.DAL) *ConsoleService {
return &ConsoleService{
dal: dal,
}
Expand Down
35 changes: 35 additions & 0 deletions backend/controller/console/console_integration_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//go:build integration

package console_test

import (
"testing"

"connectrpc.com/connect"
pbconsole "github.com/TBD54566975/ftl/backend/protos/xyz/block/ftl/v1/console"
in "github.com/TBD54566975/ftl/integration"
"github.com/alecthomas/assert/v2"
)

// GetModules calls console service GetModules and returns the response.
//
// This action is defined here vs. actions.go because it is only used in this test file.
func GetModules(onResponse func(t testing.TB, resp *connect.Response[pbconsole.GetModulesResponse])) in.Action {
return func(t testing.TB, ic in.TestContext) {
in.Infof("GetModules")
modules, err := ic.Console.GetModules(ic.Context, &connect.Request[pbconsole.GetModulesRequest]{})
assert.NoError(t, err)
onResponse(t, modules)
}
}

func TestConsoleGetModules(t *testing.T) {
in.Run(t, "",
in.CopyModule("console"),
in.Deploy("console"),
GetModules(func(t testing.TB, resp *connect.Response[pbconsole.GetModulesResponse]) {
assert.Equal(t, 1, len(resp.Msg.Modules))
assert.Equal(t, "console", resp.Msg.Modules[0].Name)
}),
)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package controller
package console

import (
"testing"
Expand Down
33 changes: 33 additions & 0 deletions backend/controller/console/testdata/go/console/console.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package console

import (
"context"
"fmt"

"ftl/builtin"

lib "github.com/TBD54566975/ftl/backend/controller/console/testdata/go"
"github.com/TBD54566975/ftl/go-runtime/ftl" // Import the FTL SDK.
)

type External = lib.External

type Response struct {
Message string
}

//ftl:ingress http GET /test
func Get(ctx context.Context, req builtin.HttpRequest[External]) (builtin.HttpResponse[Response, string], error) {
return builtin.HttpResponse[Response, string]{
Body: ftl.Some(Response{
Message: fmt.Sprintf("Hello, %s", req.Body.Message),
}),
}, nil
}

//ftl:verb
func Verb(ctx context.Context, req External) (External, error) {
return External{
Message: fmt.Sprintf("Hello, %s", req.Message),
}, nil
}
2 changes: 2 additions & 0 deletions backend/controller/console/testdata/go/console/ftl.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module = "console"
language = "go"
46 changes: 46 additions & 0 deletions backend/controller/console/testdata/go/console/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
module ftl/console

go 1.22.2

require github.com/TBD54566975/ftl v0.189.0

require (
connectrpc.com/connect v1.16.2 // indirect
connectrpc.com/grpcreflect v1.2.0 // indirect
github.com/alecthomas/atomic v0.1.0-alpha2 // indirect
github.com/alecthomas/concurrency v0.0.2 // indirect
github.com/alecthomas/participle/v2 v2.1.1 // indirect
github.com/alecthomas/types v0.16.0 // indirect
github.com/alessio/shellescape v1.4.2 // indirect
github.com/benbjohnson/clock v1.3.5 // indirect
github.com/danieljoos/wincred v1.2.0 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/godbus/dbus/v5 v5.1.0 // indirect
github.com/hashicorp/cronexpr v1.1.2 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
github.com/jackc/pgx/v5 v5.6.0 // indirect
github.com/jackc/puddle/v2 v2.2.1 // indirect
github.com/jpillora/backoff v1.0.0 // indirect
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/multiformats/go-base36 v0.2.0 // indirect
github.com/puzpuzpuz/xsync/v3 v3.4.0 // indirect
github.com/swaggest/jsonschema-go v0.3.72 // indirect
github.com/swaggest/refl v1.3.0 // indirect
github.com/zalando/go-keyring v0.2.5 // indirect
go.opentelemetry.io/otel v1.28.0 // indirect
go.opentelemetry.io/otel/metric v1.28.0 // indirect
go.opentelemetry.io/otel/trace v1.28.0 // indirect
golang.org/x/crypto v0.25.0 // indirect
golang.org/x/exp v0.0.0-20240707233637-46b078467d37 // indirect
golang.org/x/mod v0.19.0 // indirect
golang.org/x/net v0.27.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.22.0 // indirect
golang.org/x/text v0.16.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
)

replace github.com/TBD54566975/ftl => ./../../../../../..
142 changes: 142 additions & 0 deletions backend/controller/console/testdata/go/console/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions backend/controller/console/testdata/go/lib.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package lib

type External struct {
Message string
}
3 changes: 2 additions & 1 deletion backend/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (

"github.com/TBD54566975/ftl"
"github.com/TBD54566975/ftl/backend/controller/admin"
"github.com/TBD54566975/ftl/backend/controller/console"
"github.com/TBD54566975/ftl/backend/controller/cronjobs"
"github.com/TBD54566975/ftl/backend/controller/dal"
"github.com/TBD54566975/ftl/backend/controller/ingress"
Expand Down Expand Up @@ -148,7 +149,7 @@ func Start(ctx context.Context, config Config, runnerScaling scaling.RunnerScali
sm := cf.SecretsFromContext(ctx)

admin := admin.NewAdminService(cm, sm, svc.dal)
console := NewConsoleService(svc.dal)
console := console.NewService(svc.dal)

ingressHandler := http.Handler(svc)
if len(config.AllowOrigins) > 0 {
Expand Down
5 changes: 5 additions & 0 deletions integration/harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/otiai10/copy"

ftlv1 "github.com/TBD54566975/ftl/backend/protos/xyz/block/ftl/v1"
"github.com/TBD54566975/ftl/backend/protos/xyz/block/ftl/v1/console/pbconsoleconnect"
"github.com/TBD54566975/ftl/backend/protos/xyz/block/ftl/v1/ftlv1connect"
"github.com/TBD54566975/ftl/internal"
ftlexec "github.com/TBD54566975/ftl/internal/exec"
Expand Down Expand Up @@ -110,8 +111,10 @@ func run(t *testing.T, ftlConfigPath string, startController bool, actions ...Ac
verbs := rpc.Dial(ftlv1connect.NewVerbServiceClient, "http://localhost:8892", log.Debug)

var controller ftlv1connect.ControllerServiceClient
var console pbconsoleconnect.ConsoleServiceClient
if startController {
controller = rpc.Dial(ftlv1connect.NewControllerServiceClient, "http://localhost:8892", log.Debug)
console = rpc.Dial(pbconsoleconnect.NewConsoleServiceClient, "http://localhost:8892", log.Debug)

Infof("Starting ftl cluster")
ctx = startProcess(ctx, t, filepath.Join(binDir, "ftl"), "serve", "--recreate")
Expand All @@ -128,6 +131,7 @@ func run(t *testing.T, ftlConfigPath string, startController bool, actions ...Ac

if startController {
ic.Controller = controller
ic.Console = console

Infof("Waiting for controller to be ready")
ic.AssertWithRetry(t, func(t testing.TB, ic TestContext) {
Expand Down Expand Up @@ -155,6 +159,7 @@ type TestContext struct {
binDir string

Controller ftlv1connect.ControllerServiceClient
Console pbconsoleconnect.ConsoleServiceClient
Verbs ftlv1connect.VerbServiceClient
}

Expand Down

0 comments on commit 78f3a13

Please sign in to comment.