Skip to content

Commit

Permalink
add test case
Browse files Browse the repository at this point in the history
  • Loading branch information
sni committed Mar 7, 2024
1 parent 131b35e commit ad65575
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions pkg/modgearman/internal_dummy_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package modgearman

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestDummy(t *testing.T) {
cmdLine := `ENV1=test ./lib/check_dummy 0 'test output'`
cmd := parseCommand(cmdLine, &config{internalCheckDummy: true})

assert.Equal(t, Internal, cmd.ExecType, "exec type")
assert.Equal(t, &InternalCheckDummy{}, cmd.InternalCheck, "exec type")
}

func TestDummyExecute(t *testing.T) {
cfg := config{}
cfg.setDefaultValues()
cfg.encryption = false
result := &answer{}

executeCommandLine(result, &request{
commandLine: `ENV1=test ./lib/check_dummy 0 'test output'`,
timeout: 10,
}, &cfg)
assert.Equal(t, "internal", result.execType, "exec type")
assert.Equal(t, 0, result.returnCode, "return code")
assert.Equal(t, "OK: test output", result.output, "output")
}

func TestDummyExecuteWarning(t *testing.T) {
cfg := config{}
cfg.setDefaultValues()
cfg.encryption = false
result := &answer{}

executeCommandLine(result, &request{
commandLine: `ENV1=test ./lib/check_dummy 1 test' 'out"put"`,
timeout: 10,
}, &cfg)
assert.Equal(t, "internal", result.execType, "exec type")
assert.Equal(t, 1, result.returnCode, "return code")
assert.Equal(t, "WARNING: test output", result.output, "output")
}

0 comments on commit ad65575

Please sign in to comment.