Avoid rewriting the file if nothing changed

This avoids changing the indentation or number of blank lines etc unnecessarily
if nothing has changed.
This commit is contained in:
Stefan Haller
2023-06-24 13:26:51 +02:00
parent 85f293af1a
commit c4a2749a99
2 changed files with 32 additions and 13 deletions

View File

@@ -64,6 +64,14 @@ func TestUpdateYamlValue(t *testing.T) {
expectedOut: "foo:\n bar:\n baz: qux\n",
expectedErr: "",
},
{
name: "don't rewrite file if value didn't change",
in: "foo:\n bar: baz\n",
path: []string{"foo", "bar"},
value: "baz",
expectedOut: "foo:\n bar: baz\n",
expectedErr: "",
},
// Error cases
{
@@ -142,6 +150,14 @@ func TestRenameYamlKey(t *testing.T) {
expectedOut: "qux:\n bar: 5\n",
expectedErr: "",
},
{
name: "don't rewrite file if value didn't change",
in: "foo:\n bar: 5\n",
path: []string{"nonExistingKey"},
newKey: "qux",
expectedOut: "foo:\n bar: 5\n",
expectedErr: "",
},
// Error cases
{