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

     1  package install
     2  
     3  import (
     4  	"fmt"
     5  	"reflect"
     6  	"strings"
     7  	"testing"
     8  )
     9  
    10  func TestValidateKubeApiServerOptions(t *testing.T) {
    11  	tests := []struct {
    12  		opts            APIServerOptions
    13  		valid           bool
    14  		protectedFields []string
    15  	}{
    16  		{
    17  			opts:  APIServerOptions{},
    18  			valid: true,
    19  		},
    20  		{
    21  			opts: APIServerOptions{
    22  				Overrides: map[string]string{
    23  					"foobar": "baz",
    24  				},
    25  			},
    26  			valid: true,
    27  		},
    28  		{
    29  			opts: APIServerOptions{
    30  				Overrides: map[string]string{
    31  					"advertise-address": "1.2.3.4",
    32  				},
    33  			},
    34  			valid:           false,
    35  			protectedFields: []string{"advertise-address"},
    36  		},
    37  		{
    38  			opts: APIServerOptions{
    39  				Overrides: map[string]string{
    40  					"advertise-address": "1.2.3.4",
    41  					"secure-port":       "123",
    42  				},
    43  			},
    44  			valid:           false,
    45  			protectedFields: []string{"advertise-address", "secure-port"},
    46  		},
    47  		{
    48  			opts: APIServerOptions{
    49  				Overrides: map[string]string{
    50  					"advertise-address": "1.2.3.4",
    51  					"secure-port":       "123",
    52  					"v":                 "3",
    53  				},
    54  			},
    55  			valid:           false,
    56  			protectedFields: []string{"advertise-address", "secure-port"},
    57  		},
    58  	}
    59  	for _, test := range tests {
    60  		ok, err := test.opts.validate()
    61  		assertEqual(t, ok, test.valid)
    62  		if !test.valid {
    63  			assertEqual(t, err, []error{fmt.Errorf("Kube ApiServer Option(s) [%v] cannot be overridden", strings.Join(test.protectedFields, ", "))})
    64  		}
    65  	}
    66  }
    67  
    68  func assertEqual(t *testing.T, a, b interface{}) {
    69  	if !reflect.DeepEqual(a, b) {
    70  		t.Errorf("%v != %v", a, b)
    71  	}
    72  }