github.com/jlmeeker/kismatic@v1.10.1-0.20180612190640-57f9005a1f1a/pkg/cli/ip_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 TestIPCmdMissingPlan(t *testing.T) {
    11  	out := &bytes.Buffer{}
    12  	fp := &fakePlanner{
    13  		exists: false,
    14  	}
    15  	opts := &ipOpts{
    16  		planFilename: "planFile",
    17  	}
    18  	if err := doIP(out, fp, opts); err == nil {
    19  		t.Errorf("ip did not return an error when the plan does not exist")
    20  	}
    21  }
    22  
    23  func TestIPCmdEmptyAddress(t *testing.T) {
    24  	out := &bytes.Buffer{}
    25  	fp := &fakePlanner{
    26  		plan:   &install.Plan{},
    27  		exists: true,
    28  	}
    29  	opts := &ipOpts{
    30  		planFilename: "planFile",
    31  	}
    32  	if err := doIP(out, fp, opts); err == nil {
    33  		t.Errorf("ip did not return an error when LoadBalancedFQDN is empty")
    34  	}
    35  }
    36  
    37  func TestIPCmdValidAddress(t *testing.T) {
    38  	out := &bytes.Buffer{}
    39  	fp := &fakePlanner{
    40  		plan: &install.Plan{
    41  			Master: install.MasterNodeGroup{
    42  				LoadBalancedFQDN: "10.0.0.10",
    43  			},
    44  		},
    45  		exists: true,
    46  	}
    47  	opts := &ipOpts{
    48  		planFilename: "planFile",
    49  	}
    50  	err := doIP(out, fp, opts)
    51  	if err != nil {
    52  		t.Errorf("ip returned an error %v", err)
    53  	}
    54  	if out.String() != fp.plan.Master.LoadBalancedFQDN+"\n" {
    55  		t.Errorf("ip returned %s, but expectetd %s", out.String(), fp.plan.Master.LoadBalancedFQDN)
    56  	}
    57  }