From fbf88fdbdebca034dac8d9c05072ad52c4188bf5 Mon Sep 17 00:00:00 2001 From: Faeka Ansari Date: Wed, 18 Dec 2024 22:47:05 +0530 Subject: [PATCH] add a test Signed-off-by: Faeka Ansari --- internal/directives/json_updater_test.go | 33 ++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/internal/directives/json_updater_test.go b/internal/directives/json_updater_test.go index 12d194f50..6301f78dc 100644 --- a/internal/directives/json_updater_test.go +++ b/internal/directives/json_updater_test.go @@ -163,6 +163,39 @@ func Test_jsonUpdater_updateValuesFile(t *testing.T) { assert.JSONEq(t, `{"key": "value"}`, string(content)) }, }, + { + name: "preserve formatting after update", + valuesContent: `{ + "key": "value", + "nested": { + "key1": "value1", + "key2": "value2" + } + }`, + changes: map[string]any{"key": "newvalue"}, + assertions: func(t *testing.T, valuesFilePath string, err error) { + require.NoError(t, err) + + require.FileExists(t, valuesFilePath) + content, err := os.ReadFile(valuesFilePath) + require.NoError(t, err) + + updatedContent := `{ + "key": "newvalue", + "nested": { + "key1": "value1", + "key2": "value2" + } + }` + + assert.JSONEq(t, updatedContent, string(content)) + + var result map[string]any + err = json.Unmarshal(content, &result) + require.NoError(t, err) + assert.Equal(t, "newvalue", result["key"]) + }, + }, } runner := &jsonUpdater{}