github.com/jlmeeker/kismatic@v1.10.1-0.20180612190640-57f9005a1f1a/pkg/cli/apply_test.go (about)

     1  package cli
     2  
     3  import (
     4  	"bytes"
     5  	"testing"
     6  
     7  	"github.com/apprenda/kismatic/pkg/install"
     8  )
     9  
    10  func TestApplyCmdInvalidPlanFound(t *testing.T) {
    11  	out := &bytes.Buffer{}
    12  	fp := &fakePlanner{
    13  		exists: true,
    14  		plan:   &install.Plan{},
    15  	}
    16  	fe := &fakeExecutor{}
    17  
    18  	applyCmd := &applyCmd{
    19  		out:      out,
    20  		planner:  fp,
    21  		executor: fe,
    22  	}
    23  
    24  	err := applyCmd.run()
    25  
    26  	// expect an error here... we don't care about testing validation
    27  	if err == nil {
    28  		t.Error("expected error due to invalid plan, but did not get one")
    29  	}
    30  
    31  	if !fp.readCalled {
    32  		t.Error("the plan was not read")
    33  	}
    34  
    35  	if fe.installCalled {
    36  		t.Error("install was called with an invalid plan")
    37  	}
    38  }
    39  
    40  // TODO: put plan validation behind interface to enable these tests
    41  // func TestApplyCmdSkipCAGeneration(t *testing.T) {
    42  // 	out := &bytes.Buffer{}
    43  // 	fp := &fakePlanner{
    44  // 		exists: true,
    45  // 		plan:   &install.Plan{},
    46  // 	}
    47  // 	fe := &fakeExecutor{}
    48  // 	fpki := &fakePKI{}
    49  
    50  // 	applyCmd := &applyCmd{
    51  // 		out:      out,
    52  // 		planner:  fp,
    53  // 		executor: fe,
    54  // 		pki:      fpki,
    55  // 		skipCAGeneration: true
    56  // 	}
    57  
    58  // 	applyCmd.run()
    59  // 	if fpki.generateCACalled {
    60  // 		t.Errorf("generated CA when skip CA generation was set to true")
    61  // 	}
    62  
    63  // 	if !fpki.readClusterCACalled {
    64  // 		t.Errorf("did not read CA cert when skip CA generation was set to true")
    65  // 	}
    66  // }