Remove refactorring changes from coalesce_test.go

Signed-off-by: Evans Mungai <mbuevans@gmail.com>
pull/31644/head
Evans Mungai 8 months ago
parent b8937ad192
commit 0298b2ffd0
No known key found for this signature in database
GPG Key ID: BBEB812143DD14E1

@ -25,7 +25,6 @@ import (
"text/template" "text/template"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
req "github.com/stretchr/testify/require"
"helm.sh/helm/v4/pkg/chart/common" "helm.sh/helm/v4/pkg/chart/common"
chart "helm.sh/helm/v4/pkg/chart/v2" chart "helm.sh/helm/v4/pkg/chart/v2"
@ -402,8 +401,6 @@ func TestMergeValues(t *testing.T) {
} }
func TestCoalesceTables(t *testing.T) { func TestCoalesceTables(t *testing.T) {
t.Run("case 1", func(t *testing.T) {
is := assert.New(t)
dst := map[string]interface{}{ dst := map[string]interface{}{
"name": "Ishmael", "name": "Ishmael",
"address": map[string]interface{}{ "address": map[string]interface{}{
@ -435,29 +432,48 @@ func TestCoalesceTables(t *testing.T) {
// otherwise the values are coalesced. // otherwise the values are coalesced.
CoalesceTables(dst, src) CoalesceTables(dst, src)
is.Equal("Ishmael", dst["name"], "Unexpected name: %s", dst["name"]) if dst["name"] != "Ishmael" {
is.Equal("whaler", dst["occupation"], "Unexpected occupation: %s", dst["occupation"]) t.Errorf("Unexpected name: %s", dst["name"])
}
if dst["occupation"] != "whaler" {
t.Errorf("Unexpected occupation: %s", dst["occupation"])
}
addr, ok := dst["address"].(map[string]interface{}) addr, ok := dst["address"].(map[string]interface{})
req.True(t, ok, "Address went away.") if !ok {
t.Fatal("Address went away.")
is.Equal("123 Spouter Inn Ct.", addr["street"], "Unexpected address: %v", addr["street"]) }
is.Equal("Nantucket", addr["city"], "Unexpected city: %v", addr["city"])
is.Equal("MA", addr["state"], "Unexpected state: %v", addr["state"]) if addr["street"].(string) != "123 Spouter Inn Ct." {
_, ok = addr["country"] t.Errorf("Unexpected address: %v", addr["street"])
is.False(ok, "The country should be removed") }
det, ok := dst["details"].(map[string]interface{}) if addr["city"].(string) != "Nantucket" {
req.True(t, ok, "Details is the wrong type: %v", dst["details"]) t.Errorf("Unexpected city: %v", addr["city"])
_, ok = det["friends"] }
is.True(ok, "Could not find your friends. Maybe you don't have any. :-(")
if addr["state"].(string) != "MA" {
is.Equal("pequod", dst["boat"], "Expected boat string, got %v", dst["boat"]) t.Errorf("Unexpected state: %v", addr["state"])
_, ok = dst["hole"] }
is.False(ok, "The hole should be removed")
}) if _, ok = addr["country"]; ok {
t.Run("case 2", func(_ *testing.T) { t.Error("The country is not left out.")
is := assert.New(t) }
if det, ok := dst["details"].(map[string]interface{}); !ok {
t.Fatalf("Details is the wrong type: %v", dst["details"])
} else if _, ok := det["friends"]; !ok {
t.Error("Could not find your friends. Maybe you don't have any. :-(")
}
if dst["boat"].(string) != "pequod" {
t.Errorf("Expected boat string, got %v", dst["boat"])
}
if _, ok = dst["hole"]; ok {
t.Error("The hole still exists.")
}
dst2 := map[string]interface{}{ dst2 := map[string]interface{}{
"name": "Ishmael", "name": "Ishmael",
"address": map[string]interface{}{ "address": map[string]interface{}{
@ -476,46 +492,40 @@ func TestCoalesceTables(t *testing.T) {
// this happens when the --reuse-values flag is set but the chart has no modifications yet // this happens when the --reuse-values flag is set but the chart has no modifications yet
CoalesceTables(dst2, nil) CoalesceTables(dst2, nil)
is.Equal("Ishmael", dst2["name"], "Unexpected name: %s", dst2["name"]) if dst2["name"] != "Ishmael" {
t.Errorf("Unexpected name: %s", dst2["name"])
}
addr2, ok := dst2["address"].(map[string]interface{}) addr2, ok := dst2["address"].(map[string]interface{})
req.True(t, ok, "Address went away.") if !ok {
is.Equal("123 Spouter Inn Ct.", addr2["street"], "Unexpected address: %v", addr2["street"]) t.Fatal("Address went away.")
is.Equal("Nantucket", addr2["city"], "Unexpected city: %v", addr2["city"])
is.Equal("US", addr2["country"], "Unexpected country: %v", addr2["country"])
is.Equal("US", addr2["country"], "Unexpected country: %v", addr2["country"])
det2, ok := dst2["details"].(map[string]interface{})
req.True(t, ok, "Details is the wrong type: %v", dst2["details"])
_, ok = det2["friends"]
is.True(ok, "Could not find your friends. Maybe you don't have any. :-(")
is.Equal("pequod", dst2["boat"], "Expected boat string, got %v", dst2["boat"])
is.Equal("black", dst2["hole"], "Expected hole string, got %v", dst2["hole"])
})
t.Run("chart values with nil user value", func(t *testing.T) {
is := assert.New(t)
dst := map[string]any{
"foo": "bar",
"baz": nil, // explicit nil from user
} }
// Chart's default values (src - lower priority) - empty map if addr2["street"].(string) != "123 Spouter Inn Ct." {
src := map[string]any{ t.Errorf("Unexpected address: %v", addr2["street"])
"ben": nil,
} }
CoalesceTables(dst, src) if addr2["city"].(string) != "Nantucket" {
t.Errorf("Unexpected city: %v", addr2["city"])
}
// "foo" should be preserved if addr2["country"].(string) != "US" {
is.Equal("bar", dst["foo"]) t.Errorf("Unexpected Country: %v", addr2["country"])
_, ok := dst["ben"] }
is.True(ok, "Expected ben key to be present")
is.Nil(dst["ben"], "Expected ben key to be nil but it is not") if det2, ok := dst2["details"].(map[string]interface{}); !ok {
t.Fatalf("Details is the wrong type: %v", dst2["details"])
_, ok = dst["baz"] } else if _, ok := det2["friends"]; !ok {
is.True(ok, "Expected baz key to be present but it was removed") t.Error("Could not find your friends. Maybe you don't have any. :-(")
is.Nil(dst["baz"], "Expected baz key to be nil but it is not") }
})
if dst2["boat"].(string) != "pequod" {
t.Errorf("Expected boat string, got %v", dst2["boat"])
}
if dst2["hole"].(string) != "black" {
t.Errorf("Expected hole string, got %v", dst2["boat"])
}
} }
func TestMergeTables(t *testing.T) { func TestMergeTables(t *testing.T) {

Loading…
Cancel
Save