github.com/sneal/packer@v0.5.2/builder/docker/step_temp_dir_test.go (about)

     1  package docker
     2  
     3  import (
     4  	"github.com/mitchellh/multistep"
     5  	"os"
     6  	"testing"
     7  )
     8  
     9  func TestStepTempDir_impl(t *testing.T) {
    10  	var _ multistep.Step = new(StepTempDir)
    11  }
    12  
    13  func TestStepTempDir(t *testing.T) {
    14  	state := testState(t)
    15  	step := new(StepTempDir)
    16  	defer step.Cleanup(state)
    17  
    18  	// sanity test
    19  	if _, ok := state.GetOk("temp_dir"); ok {
    20  		t.Fatalf("temp_dir should not be in state yet")
    21  	}
    22  
    23  	// run the step
    24  	if action := step.Run(state); action != multistep.ActionContinue {
    25  		t.Fatalf("bad action: %#v", action)
    26  	}
    27  
    28  	// Verify that we got the temp dir
    29  	dirRaw, ok := state.GetOk("temp_dir")
    30  	if !ok {
    31  		t.Fatalf("should've made temp_dir")
    32  	}
    33  	dir := dirRaw.(string)
    34  
    35  	if _, err := os.Stat(dir); err != nil {
    36  		t.Fatalf("err: %s", err)
    37  	}
    38  
    39  	// Cleanup
    40  	step.Cleanup(state)
    41  	if _, err := os.Stat(dir); err == nil {
    42  		t.Fatalf("dir should be gone")
    43  	}
    44  }