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 good one
|
|
|
|
c = testShutdownConfig()
|
2019-10-31 10:49:34 -04:00
|
|
|
c.ShutdownTimeout = 5 * time.Second
|
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)
|
|
|
|
}
|
2019-10-31 10:49:34 -04:00
|
|
|
if c.ShutdownTimeout != 5*time.Second {
|
2015-06-21 09:06:27 -04:00
|
|
|
t.Fatalf("bad: %s", c.ShutdownTimeout)
|
|
|
|
}
|
|
|
|
}
|