Repository: helm/helm
File: pkg/chart/common/util/coalesce_test.go (Go)

Code before:
			},
			"details": map[string]interface{}{
				"friends": []string{"Tashtego"},
			},
			"boat": "pequod",
			"hole": nil,
		}
		src := map[string]interface{}{
			"occupation": "whaler",
			"address": map[string]interface{}{
				"state":   "MA",
				"street":  "234 Spouter Inn Ct.",
				"country": "US",
			},
			"details": "empty",
			"boat": map[string]interface{}{
				"mast": true,
			},
			"hole": "black",
		}

		// What we expect is that anything in dst overrides anything in src, but that
		// otherwise the values are coalesced.
		CoalesceTables(dst, src)

		is.Equal("Ishmael", dst["name"], "Unexpected name: %s", dst["name"])
		is.Equal("whaler", dst["occupation"], "Unexpected occupation: %s", dst["occupation"])

		addr, ok := dst["address"].(map[string]interface{})
		req.True(t, ok, "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"])
		_, ok = addr["country"]
		is.False(ok, "The country should be removed")

		det, ok := dst["details"].(map[string]interface{})
		req.True(t, ok, "Details is the wrong type: %v", dst["details"])
		_, ok = det["friends"]
		is.True(ok, "Could not find your friends. Maybe you don't have any. :-(")

		is.Equal("pequod", dst["boat"], "Expected boat string, got %v", dst["boat"])
		_, ok = dst["hole"]
		is.False(ok, "The hole should be removed")
	})
	t.Run("case 2", func(_ *testing.T) {
		is := assert.New(t)
		dst2 := map[string]interface{}{
			"name": "Ishmael",
			"address": map[string]interface{}{

Review comment (refactor):
Would it be okay to split this refactoring of conditional logic to `assert` into a new PR. Why `assert` (IMHO) is much better for test readability, it is difficult here to review any logic changes (due to any changes in the code logic)

Code after:
		},
		"boat": "pequod",
		"hole": nil,
	}
	src := map[string]interface{}{
		"occupation": "whaler",
		"address": map[string]interface{}{
			"state":   "MA",
			"street":  "234 Spouter Inn Ct.",
			"country": "US",
		},
		"details": "empty",
		"boat": map[string]interface{}{
			"mast": true,
		},
		"hole": "black",
	}

	// What we expect is that anything in dst overrides anything in src, but that
	// otherwise the values are coalesced.
	CoalesceTables(dst, src)

	if dst["name"] != "Ishmael" {
		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{})
	if !ok {
		t.Fatal("Address went away.")
	}

	if addr["street"].(string) != "123 Spouter Inn Ct." {
		t.Errorf("Unexpected address: %v", addr["street"])
	}

	if addr["city"].(string) != "Nantucket" {
		t.Errorf("Unexpected city: %v", addr["city"])
	}

	if addr["state"].(string) != "MA" {
		t.Errorf("Unexpected state: %v", addr["state"])
	}

	if _, ok = addr["country"]; ok {
		t.Error("The country is not left out.")
	}

	if det, ok := dst["details"].(map[string]interface{}); !ok {