open-nomad/client/driver/utils_test.go

59 lines
1.2 KiB
Go
Raw Normal View History

2016-03-08 19:07:16 +00:00
package driver
import (
2017-12-06 21:52:44 +00:00
"os"
"runtime"
"syscall"
2016-03-08 19:07:16 +00:00
"testing"
"time"
2017-12-06 21:52:44 +00:00
"github.com/stretchr/testify/assert"
2016-03-08 19:07:16 +00:00
)
func TestDriver_KillTimeout(t *testing.T) {
2017-07-21 19:06:39 +00:00
t.Parallel()
2016-03-08 19:07:16 +00:00
expected := 1 * time.Second
max := 10 * time.Second
if actual := GetKillTimeout(expected, max); expected != actual {
t.Fatalf("GetKillTimeout() returned %v; want %v", actual, expected)
}
expected = 10 * time.Second
input := 11 * time.Second
if actual := GetKillTimeout(input, max); expected != actual {
t.Fatalf("KillTimeout() returned %v; want %v", actual, expected)
}
}
2017-12-06 21:52:44 +00:00
func TestDriver_getTaskKillSignal(t *testing.T) {
assert := assert.New(t)
t.Parallel()
if runtime.GOOS != "linux" {
t.Skip("Linux only test")
}
// Test that the default is SIGINT
{
sig, err := getTaskKillSignal("")
assert.Nil(err)
assert.Equal(sig, os.Interrupt)
}
// Test that unsupported signals return an error
{
_, err := getTaskKillSignal("ABCDEF")
assert.NotNil(err)
assert.Contains(err.Error(), "Signal ABCDEF is not supported")
}
// Test that supported signals return that signal
{
sig, err := getTaskKillSignal("SIGKILL")
assert.Nil(err)
assert.Equal(sig, syscall.SIGKILL)
}
}