Skip to content

Commit

Permalink
add some integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
wesbillman committed Mar 13, 2024
1 parent 24887ee commit f2778f6
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 7 deletions.
3 changes: 0 additions & 3 deletions go-runtime/compile/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,6 @@ var scaffoldFuncs = scaffolder.FuncMap{
}
panic(fmt.Sprintf("unsupported value %T", v))
},
"isSink": func(v schema.Verb) string {
return "wes"
},
}

func genType(module *schema.Module, t schema.Type) string {
Expand Down
4 changes: 0 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ require (
github.com/radovskyb/watcher v1.0.7
github.com/rs/cors v1.10.1
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1
github.com/stretchr/testify v1.8.4
github.com/swaggest/jsonschema-go v0.3.69
github.com/titanous/json5 v1.0.0
github.com/tmc/langchaingo v0.1.5
Expand All @@ -58,13 +57,10 @@ require (

require (
github.com/google/uuid v1.6.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
github.com/ncruces/go-strftime v0.1.9 // indirect
github.com/pkoukk/tiktoken-go v0.1.2 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
go.opentelemetry.io/proto/otlp v1.1.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
modernc.org/gc/v3 v3.0.0-20240107210532-573471604cb6 // indirect
)

Expand Down
16 changes: 16 additions & 0 deletions integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,22 @@ func TestExternalCalls(t *testing.T) {
return tests
})
}
func TestPubSub(t *testing.T) {
runForRuntimes(t, func(modulesDir string, runtime string, rd runtimeData) []test {
return []test{
{name: fmt.Sprintf("PubSub%s", rd.testSuffix), assertions: assertions{
run("ftl", rd.initOpts...),
scaffoldTestData(runtime, "pubsub", rd.modulePath),
run("ftl", "deploy", rd.moduleRoot),
call(rd.moduleName, "echo", obj{}, func(t testing.TB, resp obj) {
name, ok := resp["name"].(string)
assert.True(t, ok, "name is not a string")
assert.Equal(t, "source", name)
}),
}},
}
})
}

func TestSchemaGenerate(t *testing.T) {
tests := []test{
Expand Down
49 changes: 49 additions & 0 deletions integration/testdata/go/pubsub/echo.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//ftl:module echo
package echo

import (
"context"

"github.com/TBD54566975/ftl/go-runtime/ftl"
// Import the FTL SDK.
)

type EchoRequest struct{}
type EchoResponse struct {
Name string
}

//ftl:verb
func Echo(ctx context.Context, req EchoRequest) (EchoResponse, error) {
err := ftl.CallSink(ctx, Sink, SinkRequest{})
if err != nil {
return EchoResponse{}, err
}
resp, err := ftl.CallSource(ctx, Source)
if err != nil {
return EchoResponse{}, err
}

name := resp.Name
return EchoResponse{
Name: name,
}, nil
}

type SourceResponse struct {
Name string
}

//ftl:verb
func Source(ctx context.Context) (SourceResponse, error) {
return SourceResponse{
Name: "source",
}, nil
}

type SinkRequest struct{}

//ftl:verb
func Sink(ctx context.Context, req SinkRequest) error {
return nil
}
25 changes: 25 additions & 0 deletions integration/testdata/kotlin/pubsub/Echo.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package ftl.echo

import ftl.builtin.Empty
import xyz.block.ftl.Context
import xyz.block.ftl.Verb

data class EchoResponse(val name: String)

@Verb
fun echo(context: Context, req: Empty): EchoResponse {
context.callSink(::sink, Empty())
val resp = context.callSource(::source)
return EchoResponse(name = resp.name)
}

data class SourceResponse(val name: String)

@Verb
fun source(context: Context): EchoResponse {
return EchoResponse(name = "source")
}

@Verb
fun sink(context: Context, req: Empty) {
}

0 comments on commit f2778f6

Please sign in to comment.