packer-cn/builder/docker/step_temp_dir_test.go

53 lines
992 B
Go
Raw Normal View History

2013-11-09 14:58:20 -05:00
package docker
import (
2018-01-22 19:03:49 -05:00
"context"
2013-11-09 14:58:20 -05:00
"os"
"testing"
"github.com/hashicorp/packer/helper/multistep"
2013-11-09 14:58:20 -05:00
)
func TestStepTempDir_impl(t *testing.T) {
var _ multistep.Step = new(StepTempDir)
}
func testStepTempDir_impl(t *testing.T) string {
2013-11-09 14:58:20 -05:00
state := testState(t)
step := new(StepTempDir)
defer step.Cleanup(state)
// sanity test
if _, ok := state.GetOk("temp_dir"); ok {
t.Fatalf("temp_dir should not be in state yet")
}
// run the step
2018-01-22 19:03:49 -05:00
if action := step.Run(context.Background(), state); action != multistep.ActionContinue {
2013-11-09 14:58:20 -05:00
t.Fatalf("bad action: %#v", action)
}
// Verify that we got the temp dir
dirRaw, ok := state.GetOk("temp_dir")
if !ok {
t.Fatalf("should've made temp_dir")
}
dir := dirRaw.(string)
if _, err := os.Stat(dir); err != nil {
t.Fatalf("err: %s", err)
}
// Cleanup
step.Cleanup(state)
if _, err := os.Stat(dir); err == nil {
t.Fatalf("dir should be gone")
}
return dir
}
func TestStepTempDir(t *testing.T) {
testStepTempDir_impl(t)
}