From 3128b7aaeff507e6e0f53bb22b8ad99079f9c53d Mon Sep 17 00:00:00 2001 From: Ahmed Elsabbahy Date: Mon, 25 Nov 2019 07:46:53 -0800 Subject: [PATCH] Pr 384 (#505) * Add ToUpper and ToLower to Template funcMap Add basic ToUpper and ToLower support for Template pipelines. * Add integration test * Add ToLower/ToUpper documentation * Make casing consistent on new template functions --- docs/manual.md | 2 ++ integration-tests/goss/goss-shared.yaml | 4 ++-- template.go | 2 ++ 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/docs/manual.md b/docs/manual.md index 6c1cc02db..0eaf0fb9b 100644 --- a/docs/manual.md +++ b/docs/manual.md @@ -870,6 +870,8 @@ Available functions beyond text/template [built-in functions](https://golang.org * `readFile "fileName"` - Reads file content into a string, trims whitespace. Useful when a file contains a token. * **NOTE:** Goss will error out during during the parsing phase if the file does not exist, no tests will be executed. * `regexMatch "(some)?reg[eE]xp"` - Tests the piped input against the regular expression argument. +* `toLower` - Changes piped input to lowercase +* `toUpper` - Changes piped input to UPPERCASE **NOTE:** gossfiles containing text/template `{{}}` controls will no longer work with `goss add/autoadd`. One way to get around this is to split your template and static goss files and use [gossfile](#gossfile) to import. diff --git a/integration-tests/goss/goss-shared.yaml b/integration-tests/goss/goss-shared.yaml index 19edac307..c0a5f7940 100644 --- a/integration-tests/goss/goss-shared.yaml +++ b/integration-tests/goss/goss-shared.yaml @@ -18,8 +18,8 @@ command: exit-status: 0 skip: true file: -{{range mkSlice "/etc/passwd" "/etc/group"}} - {{.}}: +{{range mkSlice "/etc/PAsswD" "/etc/group"}} + {{. | toLower}}: exists: true mode: '0644' owner: root diff --git a/template.go b/template.go index 97837b3ff..faa69bb4f 100644 --- a/template.go +++ b/template.go @@ -47,6 +47,8 @@ var funcMap = map[string]interface{}{ "readFile": readFile, "getEnv": getEnv, "regexMatch": regexMatch, + "toUpper": strings.ToUpper, + "toLower": strings.ToLower, } func NewTemplateFilter(varsFile string) func([]byte) []byte {