Skip to content

Commit

Permalink
add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
nithyatsu committed Mar 16, 2023
1 parent ce59322 commit 0af3ea8
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pkg/cli/helm/radiusclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func ApplyRadiusHelmChart(options RadiusOptions, kubeContext string) (bool, erro
}

// TODO: refactor this to use the addChartValues function
err = addRadiusValues(helmChart, &options)
err = AddRadiusValues(helmChart, &options)
if err != nil {
return false, fmt.Errorf("failed to add radius values, err: %w, helm output: %s", err, helmOutput.String())
}
Expand Down Expand Up @@ -216,7 +216,7 @@ func runRadiusHelmUpgrade(helmConf *helm.Configuration, releaseName string, helm
return runUpgrade(installClient, releaseName, helmChart)
}

func addRadiusValues(helmChart *chart.Chart, options *RadiusOptions) error {
func AddRadiusValues(helmChart *chart.Chart, options *RadiusOptions) error {
values := helmChart.Values

_, ok := values["global"]
Expand Down
53 changes: 53 additions & 0 deletions pkg/cli/helm/radiusclient_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
// ------------------------------------------------------------
package helm

import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"helm.sh/helm/v3/pkg/chart"
)

func Test_AddRadiusValues(t *testing.T) {
var helmChart chart.Chart
helmChart.Values = map[string]interface{}{}
options := &RadiusOptions{
Image: "image",
Values: "global.de.tag=de-tag,global.ucp.tag=ucp-tag,",
}
err := AddRadiusValues(&helmChart, options)
values := helmChart.Values
require.Equal(t, err, nil)

_, ok := values["global"]
assert.True(t, ok)
global := values["global"].(map[string]any)
_, ok = global["rp"]
assert.True(t, ok)
rp := global["rp"].(map[string]any)
_, ok = rp["container"]
assert.True(t, ok)
assert.Equal(t, rp["container"], "image")

_, ok = values["global"]
assert.True(t, ok)
global = values["global"].(map[string]any)
_, ok = global["de"]
assert.True(t, ok)
de := global["de"].(map[string]any)
_, ok = de["tag"]
assert.True(t, ok)
assert.Equal(t, de["tag"], "de-tag")

_, ok = global["ucp"]
assert.True(t, ok)
ucp := global["ucp"].(map[string]any)
_, ok = ucp["tag"]
assert.True(t, ok)
assert.Equal(t, ucp["tag"], "ucp-tag")

}

0 comments on commit 0af3ea8

Please sign in to comment.