-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
checker: rewrote checker.Run to return a Result directly instead of s…
…tring, error Will allow control of CRITICAL / WARNING state directly from plugins
- Loading branch information
Showing
12 changed files
with
242 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package command | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
"github.com/rbeuque74/jagozzi/plugins" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestCommand(t *testing.T) { | ||
// creating Command checker | ||
cfg := map[string]interface{}{ | ||
"command": "/bin/echo HelloWorld", | ||
"name": "test-1", | ||
} | ||
checker, err := NewCommandChecker(cfg, nil) | ||
assert.Nilf(t, err, "command checker instantiation failed: %q", err) | ||
|
||
ctxRun, cancelFunc1 := context.WithTimeout(context.Background(), time.Second) | ||
defer cancelFunc1() | ||
result := checker.Run(ctxRun) | ||
assert.Equal(t, plugins.STATE_OK, result.Status) | ||
assert.Containsf(t, result.Message, "HelloWorld\n", "command bad message: %q", result.Message) | ||
|
||
// bad exit code | ||
cfg["command"] = "/bin/false" | ||
|
||
checker, err = NewCommandChecker(cfg, nil) | ||
assert.Nilf(t, err, "command checker instantiation failed: %q", err) | ||
|
||
ctxRun, cancelFunc1 = context.WithTimeout(context.Background(), time.Second) | ||
defer cancelFunc1() | ||
result = checker.Run(ctxRun) | ||
assert.Equal(t, plugins.STATE_CRITICAL, result.Status) | ||
assert.Equal(t, result.Message, "command /bin/false exited with status code 1") | ||
|
||
// timeout | ||
cfg["command"] = "/bin/sleep 2" | ||
|
||
checker, err = NewCommandChecker(cfg, nil) | ||
assert.Nilf(t, err, "command checker instantiation failed: %q", err) | ||
|
||
ctxRun, cancelFunc1 = context.WithTimeout(context.Background(), 50*time.Millisecond) | ||
defer cancelFunc1() | ||
result = checker.Run(ctxRun) | ||
assert.Equal(t, plugins.STATE_CRITICAL, result.Status) | ||
assert.Equal(t, result.Message, "command /bin/sleep 2 took too long to execute") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.