github.com/blixtra/nomad@v0.7.2-0.20171221000451-da9a1d7bb050/client/driver/utils_test.go (about) 1 package driver 2 3 import ( 4 "os" 5 "runtime" 6 "syscall" 7 "testing" 8 "time" 9 10 "github.com/stretchr/testify/assert" 11 ) 12 13 func TestDriver_KillTimeout(t *testing.T) { 14 t.Parallel() 15 expected := 1 * time.Second 16 max := 10 * time.Second 17 18 if actual := GetKillTimeout(expected, max); expected != actual { 19 t.Fatalf("GetKillTimeout() returned %v; want %v", actual, expected) 20 } 21 22 expected = 10 * time.Second 23 input := 11 * time.Second 24 25 if actual := GetKillTimeout(input, max); expected != actual { 26 t.Fatalf("KillTimeout() returned %v; want %v", actual, expected) 27 } 28 } 29 30 func TestDriver_getTaskKillSignal(t *testing.T) { 31 assert := assert.New(t) 32 t.Parallel() 33 34 if runtime.GOOS != "linux" { 35 t.Skip("Linux only test") 36 } 37 38 // Test that the default is SIGINT 39 { 40 sig, err := getTaskKillSignal("") 41 assert.Nil(err) 42 assert.Equal(sig, os.Interrupt) 43 } 44 45 // Test that unsupported signals return an error 46 { 47 _, err := getTaskKillSignal("ABCDEF") 48 assert.NotNil(err) 49 assert.Contains(err.Error(), "Signal ABCDEF is not supported") 50 } 51 52 // Test that supported signals return that signal 53 { 54 sig, err := getTaskKillSignal("SIGKILL") 55 assert.Nil(err) 56 assert.Equal(sig, syscall.SIGKILL) 57 } 58 }