caddytest: Update Caddyfile tests for formatting, HTTP-only blocks

Previous commit improved the Caddyfile adapter so it doesn't unnecessarily add names to "skip" in "auto_https" when the server is already HTTP-only.

This commit updates the tests to reflect that change, while also fixing the Caddyfile formatting in many of the tests.

We also print the line number of the divergence between input and formatted version in Caddyfile adapt warnings - very useful for finding initial formatting problems.
This commit is contained in:
Matthew Holt
2021-01-19 14:21:11 -07:00
parent d68cff8eb6
commit 160d199999
18 changed files with 103 additions and 100 deletions

View File

@ -32,14 +32,15 @@ func TestCaddyfileAdaptToJSON(t *testing.T) {
}
// split the Caddyfile (first) and JSON (second) parts
// (append newline to Caddyfile to match formatter expectations)
parts := strings.Split(string(data), "----------")
caddyfile, json := strings.TrimSpace(parts[0]), strings.TrimSpace(parts[1])
caddyfile, json := strings.TrimSpace(parts[0])+"\n", strings.TrimSpace(parts[1])
// replace windows newlines in the json with unix newlines
json = winNewlines.ReplaceAllString(json, "\n")
// run the test
ok := caddytest.CompareAdapt(t, caddyfile, "caddyfile", json)
ok := caddytest.CompareAdapt(t, filename, caddyfile, "caddyfile", json)
if !ok {
t.Errorf("failed to adapt %s", filename)
}