2013-12-22 12:37:27 -05:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2013-12-26 10:34:27 -05:00
|
|
|
"time"
|
2013-12-22 12:37:27 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func testShutdownConfig() *ShutdownConfig {
|
|
|
|
return &ShutdownConfig{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestShutdownConfigPrepare_ShutdownCommand(t *testing.T) {
|
|
|
|
var c *ShutdownConfig
|
|
|
|
var errs []error
|
|
|
|
|
|
|
|
c = testShutdownConfig()
|
|
|
|
errs = c.Prepare(testConfigTemplate(t))
|
|
|
|
if len(errs) > 0 {
|
|
|
|
t.Fatalf("err: %#v", errs)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestShutdownConfigPrepare_ShutdownTimeout(t *testing.T) {
|
|
|
|
var c *ShutdownConfig
|
|
|
|
var errs []error
|
|
|
|
|
|
|
|
// Test with a bad value
|
|
|
|
c = testShutdownConfig()
|
|
|
|
c.RawShutdownTimeout = "this is not good"
|
|
|
|
errs = c.Prepare(testConfigTemplate(t))
|
|
|
|
if len(errs) == 0 {
|
|
|
|
t.Fatalf("should have error")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test with a good one
|
|
|
|
c = testShutdownConfig()
|
|
|
|
c.RawShutdownTimeout = "5s"
|
|
|
|
errs = c.Prepare(testConfigTemplate(t))
|
|
|
|
if len(errs) > 0 {
|
|
|
|
t.Fatalf("err: %#v", errs)
|
|
|
|
}
|
2013-12-26 10:34:27 -05:00
|
|
|
if c.ShutdownTimeout != 5*time.Second {
|
|
|
|
t.Fatalf("bad: %s", c.ShutdownTimeout)
|
|
|
|
}
|
2013-12-22 12:37:27 -05:00
|
|
|
}
|