Skip to content

Commit

Permalink
add a test
Browse files Browse the repository at this point in the history
Signed-off-by: Faeka Ansari <[email protected]>
  • Loading branch information
fykaa committed Dec 18, 2024
1 parent f07ee3b commit d2e2a34
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions internal/directives/json_updater_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down

0 comments on commit d2e2a34

Please sign in to comment.