diff options
author | Francis Lavoie <lavofr@gmail.com> | 2020-05-14 17:53:28 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-14 17:53:28 -0400 |
commit | bde3823b76b457a933e684cd096ca84fc6378997 (patch) | |
tree | 13310a50f98a15ac1a15ddcec9746eab87d057ae /caddytest/caddytest.go | |
parent | 4df56c77e380cdfec5e23862f7faa8bd843022e6 (diff) |
caddytest: Refactor Caddyfile adapt tests to separate files (#3398)
Diffstat (limited to 'caddytest/caddytest.go')
-rw-r--r-- | caddytest/caddytest.go | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/caddytest/caddytest.go b/caddytest/caddytest.go index 059b3e1..1dda345 100644 --- a/caddytest/caddytest.go +++ b/caddytest/caddytest.go @@ -321,13 +321,13 @@ func (tc *Tester) AssertRedirect(requestURI string, expectedToLocation string, e return resp } -// AssertAdapt adapts a config and then tests it against an expected result -func AssertAdapt(t *testing.T, rawConfig string, adapterName string, expectedResponse string) { +// CompareAdapt adapts a config and then compares it against an expected result +func CompareAdapt(t *testing.T, rawConfig string, adapterName string, expectedResponse string) bool { cfgAdapter := caddyconfig.GetAdapter(adapterName) if cfgAdapter == nil { - t.Errorf("unrecognized config adapter '%s'", adapterName) - return + t.Logf("unrecognized config adapter '%s'", adapterName) + return false } options := make(map[string]interface{}) @@ -335,8 +335,8 @@ func AssertAdapt(t *testing.T, rawConfig string, adapterName string, expectedRes result, warnings, err := cfgAdapter.Adapt([]byte(rawConfig), options) if err != nil { - t.Errorf("adapting config using %s adapter: %v", adapterName, err) - return + t.Logf("adapting config using %s adapter: %v", adapterName, err) + return false } if len(warnings) > 0 { @@ -369,6 +369,15 @@ func AssertAdapt(t *testing.T, rawConfig string, adapterName string, expectedRes fmt.Printf(" + %s\n", d.Payload) } } + return false + } + return true +} + +// AssertAdapt adapts a config and then tests it against an expected result +func AssertAdapt(t *testing.T, rawConfig string, adapterName string, expectedResponse string) { + ok := CompareAdapt(t, rawConfig, adapterName, expectedResponse) + if !ok { t.Fail() } } |