Abort in fileFromFixture if a replacement template is not found

This makes the fixture editation more robust against typos or unexpected
changes (if the “fixture” comes from third parties, like the OpenShift
registry configuration file).
This commit is contained in:
Miloslav Trmač 2017-04-19 23:16:04 +02:00
parent 15ce6488dd
commit cfd1cf6def

View File

@ -159,7 +159,9 @@ func fileFromFixture(c *check.C, inputPath string, edits map[string]string) stri
contents, err := ioutil.ReadFile(inputPath)
c.Assert(err, check.IsNil)
for template, value := range edits {
contents = bytes.Replace(contents, []byte(template), []byte(value), -1)
updated := bytes.Replace(contents, []byte(template), []byte(value), -1)
c.Assert(bytes.Equal(updated, contents), check.Equals, false, check.Commentf("Replacing %s in %#v failed", template, string(contents))) // Verify that the template has matched something and we are not silently ignoring it.
contents = updated
}
file, err := ioutil.TempFile("", "policy.json")