diff --git a/cmd/workflow-plugin-eventbus/plugin.go b/cmd/workflow-plugin-eventbus/plugin.go index 8f2c4cd..f2f9a2b 100644 --- a/cmd/workflow-plugin-eventbus/plugin.go +++ b/cmd/workflow-plugin-eventbus/plugin.go @@ -261,6 +261,7 @@ func (p *eventbusPlugin) ContractRegistry() *pb.ContractRegistry { { Kind: pb.ContractKind_CONTRACT_KIND_STEP, StepType: "step.eventbus.publish", + ConfigMessage: "google.protobuf.Empty", InputMessage: "workflow.plugin.eventbus.v1.PublishRequest", OutputMessage: "workflow.plugin.eventbus.v1.PublishResponse", Mode: strict, @@ -268,6 +269,7 @@ func (p *eventbusPlugin) ContractRegistry() *pb.ContractRegistry { { Kind: pb.ContractKind_CONTRACT_KIND_STEP, StepType: "step.eventbus.consume", + ConfigMessage: "google.protobuf.Empty", InputMessage: "workflow.plugin.eventbus.v1.ConsumeRequest", OutputMessage: "workflow.plugin.eventbus.v1.ConsumeResponse", Mode: strict, @@ -275,6 +277,7 @@ func (p *eventbusPlugin) ContractRegistry() *pb.ContractRegistry { { Kind: pb.ContractKind_CONTRACT_KIND_STEP, StepType: "step.eventbus.ack", + ConfigMessage: "google.protobuf.Empty", InputMessage: "workflow.plugin.eventbus.v1.AckRequest", OutputMessage: "workflow.plugin.eventbus.v1.AckResponse", Mode: strict, diff --git a/cmd/workflow-plugin-eventbus/plugin_test.go b/cmd/workflow-plugin-eventbus/plugin_test.go index 68d8ff6..0c7ef4d 100644 --- a/cmd/workflow-plugin-eventbus/plugin_test.go +++ b/cmd/workflow-plugin-eventbus/plugin_test.go @@ -11,6 +11,7 @@ import ( eventbus "github.com/GoCodeAlone/workflow-plugin-eventbus" eventbusv1 "github.com/GoCodeAlone/workflow-plugin-eventbus/gen" + pb "github.com/GoCodeAlone/workflow/plugin/external/proto" ) // TestContractRegistry_FileDescriptorSetResolvesEveryContractMessage is the @@ -64,6 +65,33 @@ func TestContractRegistry_FileDescriptorSetResolvesEveryContractMessage(t *testi } } +func TestContractRegistry_StrictStepsDeclareConfigMessage(t *testing.T) { + p := &eventbusPlugin{} + reg := p.ContractRegistry() + if reg == nil { + t.Fatal("ContractRegistry returned nil") + } + emptyConfigSteps := map[string]bool{ + "step.eventbus.publish": true, + "step.eventbus.consume": true, + "step.eventbus.ack": true, + } + for _, c := range reg.Contracts { + if c.Kind != pb.ContractKind_CONTRACT_KIND_STEP { + continue + } + if c.Mode != pb.ContractMode_CONTRACT_MODE_STRICT_PROTO { + continue + } + if c.ConfigMessage == "" { + t.Fatalf("strict step %q must declare config message so Workflow can encode TypedConfig", c.StepType) + } + if emptyConfigSteps[c.StepType] && c.ConfigMessage != "google.protobuf.Empty" { + t.Fatalf("strict step %q config message = %q, want google.protobuf.Empty", c.StepType, c.ConfigMessage) + } + } +} + func registerMessages(t *testing.T, types *protoregistry.Types, messages protoreflect.MessageDescriptors) { t.Helper() for i := 0; i < messages.Len(); i++ { diff --git a/plugin.contracts.json b/plugin.contracts.json index 107fe38..922f570 100644 --- a/plugin.contracts.json +++ b/plugin.contracts.json @@ -23,6 +23,7 @@ "kind": "step", "type": "step.eventbus.publish", "mode": "strict_proto", + "config": "google.protobuf.Empty", "input": "workflow.plugin.eventbus.v1.PublishRequest", "output": "workflow.plugin.eventbus.v1.PublishResponse" }, @@ -30,6 +31,7 @@ "kind": "step", "type": "step.eventbus.consume", "mode": "strict_proto", + "config": "google.protobuf.Empty", "input": "workflow.plugin.eventbus.v1.ConsumeRequest", "output": "workflow.plugin.eventbus.v1.ConsumeResponse" }, @@ -37,6 +39,7 @@ "kind": "step", "type": "step.eventbus.ack", "mode": "strict_proto", + "config": "google.protobuf.Empty", "input": "workflow.plugin.eventbus.v1.AckRequest", "output": "workflow.plugin.eventbus.v1.AckResponse" },