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

     1  package docker
     2  
     3  import (
     4  	"errors"
     5  	"github.com/mitchellh/multistep"
     6  	"testing"
     7  )
     8  
     9  func TestStepPull_impl(t *testing.T) {
    10  	var _ multistep.Step = new(StepPull)
    11  }
    12  
    13  func TestStepPull(t *testing.T) {
    14  	state := testState(t)
    15  	step := new(StepPull)
    16  	defer step.Cleanup(state)
    17  
    18  	config := state.Get("config").(*Config)
    19  	driver := state.Get("driver").(*MockDriver)
    20  
    21  	// run the step
    22  	if action := step.Run(state); action != multistep.ActionContinue {
    23  		t.Fatalf("bad action: %#v", action)
    24  	}
    25  
    26  	// verify we did the right thing
    27  	if !driver.PullCalled {
    28  		t.Fatal("should've pulled")
    29  	}
    30  	if driver.PullImage != config.Image {
    31  		t.Fatalf("bad: %#v", driver.PullImage)
    32  	}
    33  }
    34  
    35  func TestStepPull_error(t *testing.T) {
    36  	state := testState(t)
    37  	step := new(StepPull)
    38  	defer step.Cleanup(state)
    39  
    40  	driver := state.Get("driver").(*MockDriver)
    41  	driver.PullError = errors.New("foo")
    42  
    43  	// run the step
    44  	if action := step.Run(state); action != multistep.ActionHalt {
    45  		t.Fatalf("bad action: %#v", action)
    46  	}
    47  
    48  	// verify we have an error
    49  	if _, ok := state.GetOk("error"); !ok {
    50  		t.Fatal("should have error")
    51  	}
    52  }
    53  
    54  func TestStepPull_noPull(t *testing.T) {
    55  	state := testState(t)
    56  	step := new(StepPull)
    57  	defer step.Cleanup(state)
    58  
    59  	config := state.Get("config").(*Config)
    60  	config.Pull = false
    61  
    62  	driver := state.Get("driver").(*MockDriver)
    63  
    64  	// run the step
    65  	if action := step.Run(state); action != multistep.ActionContinue {
    66  		t.Fatalf("bad action: %#v", action)
    67  	}
    68  
    69  	// verify we did the right thing
    70  	if driver.PullCalled {
    71  		t.Fatal("shouldn't have pulled")
    72  	}
    73  }