Skip to content

Commit 777ae41

Browse files
authored
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
1 parent 282afa8 commit 777ae41

3 files changed

Lines changed: 6 additions & 2 deletions

File tree

docs/manual.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,8 @@ Available functions beyond text/template [built-in functions](https://golang.org
870870
* `readFile "fileName"` - Reads file content into a string, trims whitespace. Useful when a file contains a token.
871871
* **NOTE:** Goss will error out during during the parsing phase if the file does not exist, no tests will be executed.
872872
* `regexMatch "(some)?reg[eE]xp"` - Tests the piped input against the regular expression argument.
873+
* `toLower` - Changes piped input to lowercase
874+
* `toUpper` - Changes piped input to UPPERCASE
873875

874876
**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.
875877

integration-tests/goss/goss-shared.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ command:
1818
exit-status: 0
1919
skip: true
2020
file:
21-
{{range mkSlice "/etc/passwd" "/etc/group"}}
22-
{{.}}:
21+
{{range mkSlice "/etc/PAsswD" "/etc/group"}}
22+
{{. | toLower}}:
2323
exists: true
2424
mode: '0644'
2525
owner: root

template.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ var funcMap = map[string]interface{}{
4747
"readFile": readFile,
4848
"getEnv": getEnv,
4949
"regexMatch": regexMatch,
50+
"toUpper": strings.ToUpper,
51+
"toLower": strings.ToLower,
5052
}
5153

5254
func NewTemplateFilter(varsFile string) func([]byte) []byte {

0 commit comments

Comments
 (0)