Skip to content

Commit

Permalink
test: Add timeout test to moduleWrapper.
Browse files Browse the repository at this point in the history
  • Loading branch information
jwalton committed Apr 20, 2022
1 parent 8bd1eba commit 3b58761
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions internal/kitsch/modules/moduleWrapper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package modules
import (
"testing"
"testing/fstest"
"time"

"github.com/MakeNowJust/heredoc"
"github.com/jwalton/kitsch/internal/fileutils"
Expand Down Expand Up @@ -74,3 +75,42 @@ func TestExecuteModuleWithConditions(t *testing.T) {
result2 := mod.Execute(context)
assert.Equal(t, "", result2.Text)
}

type sleepModule struct {
// Type is the type of this module.
Type string
// Duration is the time to sleep in milliseconds.
Duration int64
// Text is the output of this module.
Text string
}

// Execute the module.
func (mod sleepModule) Execute(context *Context) ModuleResult {
time.Sleep(time.Duration(mod.Duration) * time.Millisecond)

return ModuleResult{
DefaultText: mod.Text,
Data: nil,
}
}

func TestExecuteModuleWithTimeout(t *testing.T) {
mod := ModuleWrapper{
config: CommonConfig{
Type: "sleep",
Timeout: 10,
},
Module: sleepModule{
Type: "sleep",
Duration: 1000,
Text: "Hello World",
},
}

context := newTestContext("jwalton")
result := mod.Execute(context)

// Should have no output, because it should have timed out.
assert.Equal(t, "", result.Text)
}

0 comments on commit 3b58761

Please sign in to comment.