@@ -150,7 +150,7 @@ func TestRenameYamlKey(t *testing.T) {
150150path : []string {"foo" },
151151newKey : "bar" ,
152152expectedOut : "42\n " ,
153- expectedErr : "yaml document is not a dictionary" ,
153+ expectedErr : "yaml node in path is not a dictionary" ,
154154},
155155{
156156name : "not all path elements are dictionaries" ,
@@ -171,18 +171,15 @@ func TestRenameYamlKey(t *testing.T) {
171171}
172172
173173for _ , test := range tests {
174- test := test
175174t .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