Skip to content

Commit 5a29a57

Browse files
committed
fixup! Add new function RenameYamlKey
1 parent bf37c1a commit 5a29a57

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

pkg/utils/yaml_utils/yaml_utils_test.go

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ func TestRenameYamlKey(t *testing.T) {
150150
path: []string{"foo"},
151151
newKey: "bar",
152152
expectedOut: "42\n",
153-
expectedErr: "yaml document is not a dictionary",
153+
expectedErr: "yaml node in path is not a dictionary",
154154
},
155155
{
156156
name: "not all path elements are dictionaries",
@@ -171,18 +171,15 @@ func TestRenameYamlKey(t *testing.T) {
171171
}
172172

173173
for _, test := range tests {
174-
test := test
175174
t.Run(test.name, func(t *testing.T) {
176-
out, err := RenameYamlKey([]byte(test.in), test.path, test.newKey)
177-
if test.expectedErr != "" {
178-
if err == nil {
179-
t.Errorf("expected error %q but got none", test.expectedErr)
180-
}
181-
} else if err != nil {
182-
t.Errorf("unexpected error: %v", err)
183-
} else if string(out) != test.expectedOut {
184-
t.Errorf("expected %q but got %q", test.expectedOut, string(out))
175+
out, actualErr := RenameYamlKey([]byte(test.in), test.path, test.newKey)
176+
if test.expectedErr == "" {
177+
assert.NoError(t, actualErr)
178+
} else {
179+
assert.EqualError(t, actualErr, test.expectedErr)
185180
}
181+
182+
assert.Equal(t, test.expectedOut, string(out))
186183
})
187184
}
188185
}

0 commit comments

Comments
 (0)