Skip to content

Commit

Permalink
Pr 384 (goss-org#505)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
aelsabbahy authored and BenjaminHerbert committed May 28, 2020
1 parent ae20a62 commit 3128b7a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
2 changes: 2 additions & 0 deletions docs/manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
4 changes: 2 additions & 2 deletions integration-tests/goss/goss-shared.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions template.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 3128b7a

Please sign in to comment.