package render import ( "testing" assertapi "github.com/stretchr/testify/assert" linkerd "edge-infra.dev/pkg/edge/linkerd" "edge-infra.dev/pkg/edge/linkerd/policy" "edge-infra.dev/third_party/k8s/linkerd/helm" ) var ( issuer = "test-issuer" testIssuanceLifetime = "102h0m0s" ) func TestOptions(t *testing.T) { assert := assertapi.New(t) // get all orgiginal values values, err := helm.DefaultValues() if err != nil { t.Fatal(err) } testRegistry := "test-registry" testPullSecret := "test-pull-secret-name" opts := []Option{} opts = append(opts, WithExternalIDIssuer(issuer)) opts = append(opts, WithHighAvailability()) opts = append(opts, WithAuthPolicy(policy.AllUnAuthenticated)) opts = append(opts, WithContainerRegistry(testRegistry, testPullSecret)) opts = append(opts, WithThickPosConfiguration(testIssuanceLifetime)) opts = append(opts, WithProxyIptablesMode(linkerd.IptablesModes)) // add new options to values for _, o := range opts { o(values) } // check that they were correctly set assert.Equal(values.HighAvailability, true) assert.Equal(values.IdentityTrustAnchorsPEM, issuer) assert.Equal(values.Proxy.DefaultInboundPolicy, policy.AllUnAuthenticated) assert.Equal(values.Identity.Issuer.IssuanceLifetime, testIssuanceLifetime) assert.Equal(values.ProxyInit.IptablesMode, linkerd.IptablesModes) assert.Contains(values.PolicyController.Image.Name, testRegistry) assert.Contains(values.Proxy.Image.Name, testRegistry) assert.Contains(values.ProxyInit.Image.Name, testRegistry) assert.Contains(values.DebugContainer.Image.Name, testRegistry) assert.Contains(values.ControllerImage, testRegistry) } func TestOptions_WithLogLevel(t *testing.T) { tcs := map[string]struct { params []string expected string }{ "no log expressions": {[]string{"info"}, "info"}, "enable additional global log level": {[]string{"warn", "error"}, "warn,error"}, } for name, tc := range tcs { t.Run(name, func(t *testing.T) { assert := assertapi.New(t) values, err := helm.DefaultValues() if err != nil { t.Fatal(err) } WithLogLevel(tc.params[0], tc.params[1:]...)(values) assert.Equal(tc.expected, values.PolicyController.LogLevel) assert.Equal(tc.expected, values.Proxy.LogLevel) assert.Equal(tc.params[0], values.ControllerLogLevel) }) } } func TestOptions_WithPolicyControllerLogLevel(t *testing.T) { assert := assertapi.New(t) values, err := helm.DefaultValues() if err != nil { t.Fatal(err) } WithPolicyControllerLogLevel("info,warn")(values) assert.Equal("info,warn", values.PolicyController.LogLevel) } func TestOptions_WithProxyLogLevel(t *testing.T) { assert := assertapi.New(t) values, err := helm.DefaultValues() if err != nil { t.Fatal(err) } WithProxyLogLevel("info,warn")(values) assert.Equal("info,warn", values.Proxy.LogLevel) } func TestManifests(t *testing.T) { assert := assertapi.New(t) _, err := Manifests(WithExternalIDIssuer(issuer)) assert.NoError(err) } func TestRenderUnstructured(t *testing.T) { assert := assertapi.New(t) _, err := Unstructured(WithExternalIDIssuer(issuer)) assert.NoError(err) }