Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix test case validity check #273

Merged
merged 1 commit into from
Oct 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions nagios.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,12 @@ func (p *Plugin) SkipOSExit() {
p.shouldSkipOSExit = true
}

// defaultPluginOutputTarget returns the fallback/default plugin output target
// used when a user-specified value is not provided.
func defaultPluginOutputTarget() io.Writer {
return os.Stdout
}

// emitOutput writes final plugin output to the previously set output target.
// No further modifications to plugin output are performed.
func (p Plugin) emitOutput(pluginOutput string) {
Expand Down
9 changes: 5 additions & 4 deletions unexported_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,12 @@ func TestPluginSetOutputTargetIsValidWithInvalidInput(t *testing.T) {
t.Log("Attempting to set invalid output target. This should cause the default output sink to be set instead.")
plugin.SetOutputTarget(nil)

// Assert that plugin.outputSink is set to a non-nil default/fallback
// value as expected.
if plugin.outputSink == nil {
switch {
case plugin.outputSink == nil:
t.Fatal("ERROR: plugin outputSink is still unset.")
case plugin.outputSink != defaultPluginOutputTarget():
t.Fatal("ERROR: plugin outputSink is not at the expected default/fallback value.")
} else {
default:
t.Log("OK: plugin outputSink is at the expected default/fallback value.")
}
}
Expand Down
Loading