2019-06-13 11:23:21 -04:00
|
|
|
package shutdowncommand
|
2015-06-21 09:06:27 -04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
"time"
|
2019-06-14 04:55:10 -04:00
|
|
|
|
|
|
|
"github.com/hashicorp/packer/template/interpolate"
|
2015-06-21 09:06:27 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func testShutdownConfig() *ShutdownConfig {
|
|
|
|
return &ShutdownConfig{}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestShutdownConfigPrepare_ShutdownCommand(t *testing.T) {
|
|
|
|
var c *ShutdownConfig
|
|
|
|
var errs []error
|
|
|
|
|
|
|
|
c = testShutdownConfig()
|
2019-06-14 04:55:10 -04:00
|
|
|
errs = c.Prepare(interpolate.NewContext())
|
2015-06-21 09:06:27 -04:00
|
|
|
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"
|
2019-06-14 04:55:10 -04:00
|
|
|
errs = c.Prepare(interpolate.NewContext())
|
2015-06-21 09:06:27 -04:00
|
|
|
if len(errs) == 0 {
|
|
|
|
t.Fatalf("should have error")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test with a good one
|
|
|
|
c = testShutdownConfig()
|
|
|
|
c.RawShutdownTimeout = "5s"
|
2019-06-14 04:55:10 -04:00
|
|
|
errs = c.Prepare(interpolate.NewContext())
|
2015-06-21 09:06:27 -04:00
|
|
|
if len(errs) > 0 {
|
|
|
|
t.Fatalf("err: %#v", errs)
|
|
|
|
}
|
|
|
|
if c.ShutdownTimeout != 5*time.Second {
|
|
|
|
t.Fatalf("bad: %s", c.ShutdownTimeout)
|
|
|
|
}
|
|
|
|
}
|