...

Source file src/edge-infra.dev/pkg/edge/linkerd/helm/render/render_test.go

Documentation: edge-infra.dev/pkg/edge/linkerd/helm/render

     1  package render
     2  
     3  import (
     4  	"testing"
     5  
     6  	assertapi "github.com/stretchr/testify/assert"
     7  
     8  	linkerd "edge-infra.dev/pkg/edge/linkerd"
     9  	"edge-infra.dev/pkg/edge/linkerd/policy"
    10  	"edge-infra.dev/third_party/k8s/linkerd/helm"
    11  )
    12  
    13  var (
    14  	issuer               = "test-issuer"
    15  	testIssuanceLifetime = "102h0m0s"
    16  )
    17  
    18  func TestOptions(t *testing.T) {
    19  	assert := assertapi.New(t)
    20  
    21  	// get all orgiginal values
    22  	values, err := helm.DefaultValues()
    23  	if err != nil {
    24  		t.Fatal(err)
    25  	}
    26  
    27  	testRegistry := "test-registry"
    28  	testPullSecret := "test-pull-secret-name"
    29  
    30  	opts := []Option{}
    31  	opts = append(opts, WithExternalIDIssuer(issuer))
    32  	opts = append(opts, WithHighAvailability())
    33  	opts = append(opts, WithAuthPolicy(policy.AllUnAuthenticated))
    34  	opts = append(opts, WithContainerRegistry(testRegistry, testPullSecret))
    35  	opts = append(opts, WithThickPosConfiguration(testIssuanceLifetime))
    36  	opts = append(opts, WithProxyIptablesMode(linkerd.IptablesModes))
    37  
    38  	// add new options to values
    39  	for _, o := range opts {
    40  		o(values)
    41  	}
    42  
    43  	// check that they were correctly set
    44  	assert.Equal(values.HighAvailability, true)
    45  	assert.Equal(values.IdentityTrustAnchorsPEM, issuer)
    46  	assert.Equal(values.Proxy.DefaultInboundPolicy, policy.AllUnAuthenticated)
    47  	assert.Equal(values.Identity.Issuer.IssuanceLifetime, testIssuanceLifetime)
    48  	assert.Equal(values.ProxyInit.IptablesMode, linkerd.IptablesModes)
    49  	assert.Contains(values.PolicyController.Image.Name, testRegistry)
    50  	assert.Contains(values.Proxy.Image.Name, testRegistry)
    51  	assert.Contains(values.ProxyInit.Image.Name, testRegistry)
    52  	assert.Contains(values.DebugContainer.Image.Name, testRegistry)
    53  	assert.Contains(values.ControllerImage, testRegistry)
    54  }
    55  
    56  func TestOptions_WithLogLevel(t *testing.T) {
    57  	tcs := map[string]struct {
    58  		params   []string
    59  		expected string
    60  	}{
    61  		"no log expressions":                 {[]string{"info"}, "info"},
    62  		"enable additional global log level": {[]string{"warn", "error"}, "warn,error"},
    63  	}
    64  
    65  	for name, tc := range tcs {
    66  		t.Run(name, func(t *testing.T) {
    67  			assert := assertapi.New(t)
    68  
    69  			values, err := helm.DefaultValues()
    70  			if err != nil {
    71  				t.Fatal(err)
    72  			}
    73  			WithLogLevel(tc.params[0], tc.params[1:]...)(values)
    74  
    75  			assert.Equal(tc.expected, values.PolicyController.LogLevel)
    76  			assert.Equal(tc.expected, values.Proxy.LogLevel)
    77  			assert.Equal(tc.params[0], values.ControllerLogLevel)
    78  		})
    79  	}
    80  }
    81  
    82  func TestOptions_WithPolicyControllerLogLevel(t *testing.T) {
    83  	assert := assertapi.New(t)
    84  
    85  	values, err := helm.DefaultValues()
    86  	if err != nil {
    87  		t.Fatal(err)
    88  	}
    89  
    90  	WithPolicyControllerLogLevel("info,warn")(values)
    91  	assert.Equal("info,warn", values.PolicyController.LogLevel)
    92  }
    93  
    94  func TestOptions_WithProxyLogLevel(t *testing.T) {
    95  	assert := assertapi.New(t)
    96  
    97  	values, err := helm.DefaultValues()
    98  	if err != nil {
    99  		t.Fatal(err)
   100  	}
   101  
   102  	WithProxyLogLevel("info,warn")(values)
   103  	assert.Equal("info,warn", values.Proxy.LogLevel)
   104  }
   105  
   106  func TestManifests(t *testing.T) {
   107  	assert := assertapi.New(t)
   108  	_, err := Manifests(WithExternalIDIssuer(issuer))
   109  	assert.NoError(err)
   110  }
   111  
   112  func TestRenderUnstructured(t *testing.T) {
   113  	assert := assertapi.New(t)
   114  	_, err := Unstructured(WithExternalIDIssuer(issuer))
   115  	assert.NoError(err)
   116  }
   117  

View as plain text