github.com/kubernetes-incubator/kube-aws@v0.16.4/pkg/api/worker_node_pool_test.go (about)

     1  package api
     2  
     3  import (
     4  	"testing"
     5  )
     6  
     7  func intp(v int) *int {
     8  	return &v
     9  }
    10  
    11  func nodePoolWithCount(n int) WorkerNodePool {
    12  	return WorkerNodePool{
    13  		EC2Instance: EC2Instance{
    14  			Count: n,
    15  		},
    16  	}
    17  }
    18  
    19  func nodePoolWithMinSize(n int) WorkerNodePool {
    20  	return WorkerNodePool{
    21  		AutoScalingGroup: AutoScalingGroup{
    22  			MinSize: intp(n),
    23  		},
    24  	}
    25  }
    26  
    27  func nodePoolWithMaxSize(n int) WorkerNodePool {
    28  	return WorkerNodePool{
    29  		AutoScalingGroup: AutoScalingGroup{
    30  			MaxSize: n,
    31  		},
    32  	}
    33  }
    34  
    35  func nodePoolWithCountAndMinInService(n int, minInService int) WorkerNodePool {
    36  	return WorkerNodePool{
    37  		EC2Instance: EC2Instance{
    38  			Count: n,
    39  		},
    40  		AutoScalingGroup: AutoScalingGroup{
    41  			RollingUpdateMinInstancesInService: intp(minInService),
    42  		},
    43  	}
    44  }
    45  
    46  func TestNodePoolMinCount(t *testing.T) {
    47  	c1 := nodePoolWithCount(0)
    48  	if c1.MinCount() != 0 {
    49  		t.Errorf("min count should be 0 but was %d in %+v", c1.MinCount(), c1)
    50  	}
    51  
    52  	c2 := nodePoolWithCount(2)
    53  	if c2.MinCount() != 2 {
    54  		t.Errorf("min count should be 2 but was %d in %+v", c2.MinCount(), c2)
    55  	}
    56  
    57  	c3 := nodePoolWithMinSize(0)
    58  	if c3.MinCount() != 0 {
    59  		t.Errorf("min count should be 0 but was %d in %+v", c3.MinCount(), c3)
    60  	}
    61  
    62  	c4 := nodePoolWithMinSize(2)
    63  	if c4.MinCount() != 2 {
    64  		t.Errorf("min count should be 2 but was %d in %+v", c4.MinCount(), c4)
    65  	}
    66  }
    67  
    68  func TestNodePoolMaxCount(t *testing.T) {
    69  	c1 := nodePoolWithCount(0)
    70  	if c1.MaxCount() != 0 {
    71  		t.Errorf("max count should be 0 but was %d in %+v", c1.MaxCount(), c1)
    72  	}
    73  
    74  	c2 := nodePoolWithCount(2)
    75  	if c2.MaxCount() != 2 {
    76  		t.Errorf("max count should be 2 but was %d in %+v", c2.MaxCount(), c2)
    77  	}
    78  
    79  	c3 := nodePoolWithMaxSize(0)
    80  	if c3.MaxCount() != 0 {
    81  		t.Errorf("max count should be 0 but was %d in %+v", c3.MaxCount(), c3)
    82  	}
    83  
    84  	c4 := nodePoolWithMaxSize(2)
    85  	if c4.MaxCount() != 2 {
    86  		t.Errorf("max count should be 2 but was %d in %+v", c4.MaxCount(), c4)
    87  	}
    88  }
    89  
    90  func TestNodePoolRollingUpdateMinInstancesInService(t *testing.T) {
    91  	c1 := nodePoolWithCount(0)
    92  	if c1.RollingUpdateMinInstancesInService() != 0 {
    93  		t.Errorf("min instances in service should be 0 but was %d in %+v", c1.RollingUpdateMinInstancesInService(), c1)
    94  	}
    95  
    96  	c2 := nodePoolWithCount(2)
    97  	if c2.RollingUpdateMinInstancesInService() != 1 {
    98  		t.Errorf("min instances in service should be 2 but was %d in %+v", c2.RollingUpdateMinInstancesInService(), c2)
    99  	}
   100  
   101  	c3 := nodePoolWithMinSize(2)
   102  	if c3.RollingUpdateMinInstancesInService() != 1 {
   103  		t.Errorf("min instances in service should be 2 but was %d in %+v", c3.RollingUpdateMinInstancesInService(), c3)
   104  	}
   105  
   106  	c4 := nodePoolWithMaxSize(2)
   107  	if c4.RollingUpdateMinInstancesInService() != 1 {
   108  		t.Errorf("min instances in service should be 2 but was %d in %+v", c4.RollingUpdateMinInstancesInService(), c4)
   109  	}
   110  
   111  	c5 := nodePoolWithCountAndMinInService(2, 0)
   112  	if c5.RollingUpdateMinInstancesInService() != 0 {
   113  		t.Errorf("min instances in service should be 0 but was %d in %+v", c5.RollingUpdateMinInstancesInService(), c5)
   114  	}
   115  
   116  	c6 := nodePoolWithCountAndMinInService(0, 2)
   117  	if c6.RollingUpdateMinInstancesInService() != 2 {
   118  		t.Errorf("min instances in service should be 2 but was %d in %+v", c6.RollingUpdateMinInstancesInService(), c6)
   119  	}
   120  }