Skip to content

Commit

Permalink
fix: ftltest pubsub needs context associated with fake ftl (#2186)
Browse files Browse the repository at this point in the history
fixes #2184
Could not repro easily in a test but was able to repro in partner
project. Will look inout the tests during the week
  • Loading branch information
matt2e authored Jul 27, 2024
1 parent b9908a6 commit 48bc91d
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
8 changes: 4 additions & 4 deletions go-runtime/ftl/ftltest/fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,17 @@ type fakeFTL struct {
// type but is not constrained by input/output type like ftl.Map.
type mapImpl func(context.Context) (any, error)

func newFakeFTL(ctx context.Context) *fakeFTL {
func contextWithFakeFTL(ctx context.Context) context.Context {
fake := &fakeFTL{
fsm: newFakeFSMManager(),
mockMaps: map[uintptr]mapImpl{},
allowMapCalls: false,
configValues: map[string][]byte{},
secretValues: map[string][]byte{},
pubSub: newFakePubSub(ctx),
}

return fake
ctx = internal.WithContext(ctx, fake)
fake.pubSub = newFakePubSub(ctx)
return ctx
}

var _ internal.FTL = &fakeFTL{}
Expand Down
2 changes: 1 addition & 1 deletion go-runtime/ftl/ftltest/ftltest.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func Context(options ...Option) context.Context {
}

ctx := log.ContextWithNewDefaultLogger(context.Background())
ctx = internal.WithContext(ctx, newFakeFTL(ctx))
ctx = contextWithFakeFTL(ctx)
name := reflection.Module()

sort.Slice(options, func(i, j int) bool {
Expand Down
3 changes: 1 addition & 2 deletions go-runtime/ftl/ftltest/ftltest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"testing"

"github.com/TBD54566975/ftl/go-runtime/ftl"
"github.com/TBD54566975/ftl/go-runtime/internal"
"github.com/TBD54566975/ftl/internal/log"
"github.com/alecthomas/assert/v2"
)
Expand All @@ -27,7 +26,7 @@ func PanicsWithErr(t testing.TB, substr string, fn func()) {

func TestFtlTestProjectNotLoadedInContext(t *testing.T) {
ctx := log.ContextWithNewDefaultLogger(context.Background())
ctx = internal.WithContext(ctx, newFakeFTL(ctx))
ctx = contextWithFakeFTL(ctx)

// This should panic suggesting to use ftltest.WithDefaultProjectFile()
PanicsWithErr(t, "ftltest.WithDefaultProjectFile()", func() {
Expand Down

0 comments on commit 48bc91d

Please sign in to comment.