Skip to content

test: add unit tests for bento plugin modules, steps, and triggers#10

Merged
intel352 merged 1 commit intomainfrom
feat/issue-2-unit-tests
Feb 23, 2026
Merged

test: add unit tests for bento plugin modules, steps, and triggers#10
intel352 merged 1 commit intomainfrom
feat/issue-2-unit-tests

Conversation

@intel352
Copy link
Contributor

Summary

  • Add unit tests for all module types (stream, input, output, broker)
  • Add unit tests for processor step (including Bloblang execution via pure components)
  • Add unit tests for bento trigger
  • Add plugin provider tests covering all factory methods and schema
  • Add bridge helper tests (configToYAML, messageToMap, mapToMessage, round-trip)
  • Cover success and error paths for each component
  • Fix two pre-existing lint issues (errcheck in bridge.go, nolint for scaffolded ensureStream)

Closes #2

Test plan

  • All 88 tests pass with -race flag
  • golangci-lint run passes with 0 issues
  • Build passes (go build ./...)

Notes

  • Tests focus on what is testable without running real external Bento streams: constructors, config validation, field parsing, error cases, and module metadata
  • The processor step test exercises actual Bloblang execution using an in-process stream with the pure components side-effect import
  • The TestStreamModule_Stop_WithoutStart test correctly handles the blocking done channel by relying on context cancellation

Copilot AI review requested due to automatic review settings February 23, 2026 11:18
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds comprehensive unit test coverage across the Bento plugin’s modules (stream/input/output/broker), processor step, and trigger, plus bridge helper conversions, aiming to validate constructors, config parsing, and error paths without running external Bento streams.

Changes:

  • Added new unit tests for module instances, trigger parsing, processor step execution, and plugin provider factory/schema behavior.
  • Added bridge helper tests for YAML conversion and message/map conversions (including a basic round-trip).
  • Minor lint-related tweaks (errcheck-related change in bridge.go, and nolint annotation in broker_module.go).

Reviewed changes

Copilot reviewed 11 out of 12 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
internal/trigger_test.go Tests trigger construction and subscription parsing/error cases.
internal/stream_module_test.go Tests stream module constructor/init/stop behaviors.
internal/processor_step_test.go Tests processor step config parsing and execution (including Bloblang via pure components).
internal/plugin_test.go Tests plugin provider manifest, factories, and schema presence.
internal/output_module_test.go Tests output module init validation and message wiring setters.
internal/input_module_test.go Tests input module init validation and provides mocks used by other tests.
internal/broker_module_test.go Tests broker defaults/config parsing and message wiring setters.
internal/broker_module.go Adds nolint for an intentionally-unused helper.
internal/bridge_test.go Tests config/map/message conversion helpers.
internal/bridge.go Adjusts handling of returned error from MetaWalkMut.
go.mod / go.sum Updates dependencies pulled in by new tests/components.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +42 to 45
_ = msg.MetaWalkMut(func(key string, value any) error {
meta[key] = value
return nil
})
Copy link

Copilot AI Feb 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

messageToMap is explicitly discarding the error returned by msg.MetaWalkMut. If MetaWalkMut can return an error (e.g., from internal iteration), we should handle it and propagate/annotate it so metadata-copy failures don’t get silently ignored.

Suggested change
_ = msg.MetaWalkMut(func(key string, value any) error {
meta[key] = value
return nil
})
if err := msg.MetaWalkMut(func(key string, value any) error {
meta[key] = value
return nil
}); err != nil {
return nil, fmt.Errorf("copy message metadata: %w", err)
}

Copilot uses AI. Check for mistakes.
Comment on lines +223 to +227
reconstructed := mapToMessage(m)
if reconstructed == nil {
t.Fatal("mapToMessage() returned nil")
}
}
Copy link

Copilot AI Feb 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This round-trip test only checks that mapToMessage returns non-nil, but it doesn’t assert that the reconstructed message preserves the original body and metadata. Add assertions (e.g., compare AsBytes() and MetaGet values) so the test will fail if the conversion logic regresses.

Copilot generated this review using guidance from organization custom instructions.
@intel352
Copy link
Contributor Author

@copilot open a new pull request to apply changes based on the comments in this thread

Copy link
Contributor

Copilot AI commented Feb 23, 2026

@intel352 I've opened a new pull request, #11, to work on those changes. Once the pull request is ready, I'll request review from you.

- Add plugin_test.go: covers Manifest(), ModuleTypes(), StepTypes(),
  TriggerTypes(), CreateModule/Step/Trigger for all valid and unknown types,
  ModuleSchemas(), and interface satisfaction at runtime
- Add stream_module_test.go: constructor, Init() validation (empty config),
  Name field, Stop without Start, config storage, done channel
- Add input_module_test.go: constructor, Init() validation (missing/empty
  target_topic, missing input config), topic/broker field parsing,
  SetMessagePublisher/Subscriber, MessageAwareModule interface
- Add output_module_test.go: constructor, Init() validation (missing/empty
  source_topic, missing output config), topic/broker field parsing,
  SetMessageSubscriber/Publisher, MessageAwareModule interface
- Add broker_module_test.go: constructor, Init() default transport "memory",
  explicit transport, transport_config storage, publisher/subscriber injection,
  streams map initialization, Start no-op, MessageAwareModule interface
- Add processor_step_test.go: constructor with string/map/nil processors,
  invalid type error, Name field, Execute pass-through, current-overrides-trigger
  merge, empty inputs, bloblang pass-through, context cancel, StopPipeline=false
- Add bridge_test.go: configToYAML (simple, nested, empty), messageToMap
  (JSON body, plain-text body, metadata, empty), mapToMessage (string body,
  JSON body, no body, metadata, empty), round-trip
- Import pure Bento components in processor tests to enable bloblang processor
- Fix pre-existing lint issues: errcheck in bridge.go, nolint for scaffolded
  ensureStream in broker_module.go

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings February 23, 2026 14:33
@intel352 intel352 force-pushed the feat/issue-2-unit-tests branch from af6eab3 to 45c0625 Compare February 23, 2026 14:33
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@intel352 intel352 merged commit 006be83 into main Feb 23, 2026
12 checks passed
@intel352 intel352 deleted the feat/issue-2-unit-tests branch February 23, 2026 16:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add unit and integration tests for modules, steps, and triggers

3 participants