Skip to content

Commit fe22bab

Browse files
connector: Use API interface to improve testability of connector funcs (#87)
1 parent 987d363 commit fe22bab

File tree

6 files changed

+14
-9
lines changed

6 files changed

+14
-9
lines changed

_examples/connector/connector.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,15 @@ func Workflow(d Deps) *workflow.Workflow[GettingStarted, Status] {
5050
builder.AddConnector(
5151
"my-example-connector",
5252
d.Connector,
53-
func(ctx context.Context, w *workflow.Workflow[GettingStarted, Status], e *workflow.ConnectorEvent) error {
54-
_, err := w.Trigger(ctx, e.ForeignID, StatusStarted, workflow.WithInitialValue[GettingStarted, Status](&GettingStarted{
55-
ReadTheDocs: "✅",
56-
}))
53+
func(ctx context.Context, w workflow.API[GettingStarted, Status], e *workflow.ConnectorEvent) error {
54+
_, err := w.Trigger(
55+
ctx,
56+
e.ForeignID,
57+
StatusStarted,
58+
workflow.WithInitialValue[GettingStarted, Status](&GettingStarted{
59+
ReadTheDocs: "✅",
60+
}),
61+
)
5762
if err != nil {
5863
return err
5964
}

adapters/adaptertest/connector.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func RunConnectorTest(t *testing.T, maker func(seedEvents []workflow.ConnectorEv
3434
builder.AddConnector(
3535
"tester",
3636
constructor,
37-
func(ctx context.Context, w *workflow.Workflow[User, SyncStatus], e *workflow.ConnectorEvent) error {
37+
func(ctx context.Context, w workflow.API[User, SyncStatus], e *workflow.ConnectorEvent) error {
3838
_, err := w.Trigger(ctx, e.ForeignID, SyncStatusStarted, workflow.WithInitialValue[User, SyncStatus](&User{
3939
UID: e.ForeignID,
4040
}))

builder_internal_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ func TestAddTimeoutDontAllowLag(t *testing.T) {
232232
}
233233

234234
func TestConnectorConstruction(t *testing.T) {
235-
fn := func(ctx context.Context, w *Workflow[string, testStatus], e *ConnectorEvent) error {
235+
fn := func(ctx context.Context, w API[string, testStatus], e *ConnectorEvent) error {
236236
return nil
237237
}
238238

connector.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ type ConnectorConsumer interface {
1717
Close() error
1818
}
1919

20-
type ConnectorFunc[Type any, Status StatusType] func(ctx context.Context, w *Workflow[Type, Status], e *ConnectorEvent) error
20+
type ConnectorFunc[Type any, Status StatusType] func(ctx context.Context, w API[Type, Status], e *ConnectorEvent) error
2121

2222
type connectorConfig[Type any, Status StatusType] struct {
2323
name string

state_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func TestInternalState(t *testing.T) {
3838
b.AddConnector(
3939
"consume-other-stream",
4040
memstreamer.NewConnector(nil),
41-
func(ctx context.Context, w *workflow.Workflow[string, status], e *workflow.ConnectorEvent) error {
41+
func(ctx context.Context, w workflow.API[string, status], e *workflow.ConnectorEvent) error {
4242
return nil
4343
},
4444
).WithOptions(

workflow_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ func TestConnector(t *testing.T) {
519519
buidler.AddConnector(
520520
"my-test-connector",
521521
connector,
522-
func(ctx context.Context, w *workflow.Workflow[typeX, status], e *workflow.ConnectorEvent) error {
522+
func(ctx context.Context, w workflow.API[typeX, status], e *workflow.ConnectorEvent) error {
523523
_, err := w.Trigger(ctx, e.ForeignID, StatusStart, workflow.WithInitialValue[typeX, status](&typeX{
524524
Val: "trigger set value",
525525
}))

0 commit comments

Comments
 (0)