From 15647bdfb757ab7b1d1c77446a0707e49f31deb7 Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Tue, 18 Jun 2019 15:43:51 -0600 Subject: templates: Remove context functions implemented by sprig --- modules/caddyhttp/templates/tplcontext_test.go | 131 ------------------------- 1 file changed, 131 deletions(-) (limited to 'modules/caddyhttp/templates/tplcontext_test.go') diff --git a/modules/caddyhttp/templates/tplcontext_test.go b/modules/caddyhttp/templates/tplcontext_test.go index af4ad4e..efe5374 100644 --- a/modules/caddyhttp/templates/tplcontext_test.go +++ b/modules/caddyhttp/templates/tplcontext_test.go @@ -109,42 +109,6 @@ func TestCookieMultipleCookies(t *testing.T) { } } -func TestEnv(t *testing.T) { - context := getContextOrFail(t) - - name := "ENV_TEST_NAME" - testValue := "TEST_VALUE" - os.Setenv(name, testValue) - - notExisting := "ENV_TEST_NOT_EXISTING" - os.Unsetenv(notExisting) - - invalidName := "ENV_TEST_INVALID_NAME" - os.Setenv("="+invalidName, testValue) - - env := context.Env() - if value := env[name]; value != testValue { - t.Errorf("Expected env-variable %s value '%s', found '%s'", - name, testValue, value) - } - - if value, ok := env[notExisting]; ok { - t.Errorf("Expected empty env-variable %s, found '%s'", - notExisting, value) - } - - for k, v := range env { - if strings.Contains(k, invalidName) { - t.Errorf("Expected invalid name not to be included in Env %s, found in key '%s'", invalidName, k) - } - if strings.Contains(v, invalidName) { - t.Errorf("Expected invalid name not be be included in Env %s, found in value '%s'", invalidName, v) - } - } - - os.Unsetenv("=" + invalidName) -} - func TestIP(t *testing.T) { context := getContextOrFail(t) for i, test := range []struct { @@ -164,57 +128,6 @@ func TestIP(t *testing.T) { } } -func TestTruncate(t *testing.T) { - context := getContextOrFail(t) - - for i, test := range []struct { - input string - length int - expect string - }{ - { - input: "string", - length: 1, - expect: "s", - }, - { - input: "string", - length: 6, - expect: "string", - }, - { - input: "string", - length: 10, - expect: "string", - }, - { - input: "string", - length: 0, - expect: "", - }, - { - input: "string", - length: -5, - expect: "tring", - }, - { - input: "string", - length: -6, - expect: "string", - }, - { - input: "string", - length: -7, - expect: "string", - }, - } { - actual := context.Truncate(test.input, test.length) - if actual != test.expect { - t.Errorf("Test %d: Expected '%s' but got '%s'", i, test.expect, actual) - } - } -} - func TestStripHTML(t *testing.T) { context := getContextOrFail(t) @@ -260,50 +173,6 @@ func TestStripHTML(t *testing.T) { } } -func TestStripExt(t *testing.T) { - context := getContextOrFail(t) - tests := []struct { - input string - expect string - }{ - { - input: "", - expect: "", - }, - { - input: "file.ext", - expect: "file", - }, - { - input: "file", - expect: "file", - }, - { - input: "/file", - expect: "/file", - }, - { - input: "/file.ext", - expect: "/file", - }, - { - input: "/dir.ext/", - expect: "/dir.ext/", - }, - { - input: "/dir.ext/file.ext", - expect: "/dir.ext/file", - }, - } - - for i, test := range tests { - actual := context.StripExt(test.input) - if actual != test.expect { - t.Errorf("Test %d: Expected %s but got %s", i, test.expect, actual) - } - } -} - func TestFileListing(t *testing.T) { for i, test := range []struct { fileNames []string -- cgit v1.2.3