From cfd1cf6def2c135e16f51517fb1bd2d6c0803f4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miloslav=20Trma=C4=8D?= Date: Wed, 19 Apr 2017 23:16:04 +0200 Subject: [PATCH] Abort in fileFromFixture if a replacement template is not found MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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). --- integration/utils.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/integration/utils.go b/integration/utils.go index 51eff3c5..0eea8a1f 100644 --- a/integration/utils.go +++ b/integration/utils.go @@ -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")