Bump sprig@latest
This commit is contained in:
7
vendor/github.com/Masterminds/sprig/README.md
generated
vendored
7
vendor/github.com/Masterminds/sprig/README.md
generated
vendored
@@ -166,6 +166,13 @@ parse, it returns the time unaltered. See `time.ParseDuration` for info on durat
|
||||
follows: []byte are converted, fmt.Stringers will have String() called.
|
||||
errors will have Error() called. All others will be passed through
|
||||
fmt.Sprtinf("%v").
|
||||
- set: Takes a dict, a key, and a value, and sets that key/value pair in
|
||||
the dict. `set $dict $key $value`. For convenience, it returns the dict,
|
||||
even though the dict was modified in place.
|
||||
- unset: Takes a dict and a key, and deletes that key/value pair from the
|
||||
dict. `unset $dict $key`. This returns the dict for convenience.
|
||||
- hasKey: Takes a dict and a key, and returns boolean true if the key is in
|
||||
the dict.
|
||||
|
||||
```
|
||||
{{$t := tuple 1 "a" "foo"}}
|
||||
|
45
vendor/github.com/Masterminds/sprig/functions.go
generated
vendored
45
vendor/github.com/Masterminds/sprig/functions.go
generated
vendored
@@ -99,6 +99,14 @@ OS:
|
||||
- env: Resolve an environment variable
|
||||
- expandenv: Expand a string through the environment
|
||||
|
||||
File Paths:
|
||||
- base: Return the last element of a path. https://golang.org/pkg/path#Base
|
||||
- dir: Remove the last element of a path. https://golang.org/pkg/path#Dir
|
||||
- clean: Clean a path to the shortest equivalent name. (e.g. remove "foo/.."
|
||||
from "foo/../bar.html") https://golang.org/pkg/path#Clean
|
||||
- ext: https://golang.org/pkg/path#Ext
|
||||
- isAbs: https://golang.org/pkg/path#IsAbs
|
||||
|
||||
Encoding:
|
||||
- b64enc: Base 64 encode a string.
|
||||
- b64dec: Base 64 decode a string.
|
||||
@@ -135,6 +143,13 @@ Data Structures:
|
||||
follows: []byte are converted, fmt.Stringers will have String() called.
|
||||
errors will have Error() called. All others will be passed through
|
||||
fmt.Sprtinf("%v").
|
||||
- set: Takes a dict, a key, and a value, and sets that key/value pair in
|
||||
the dict. `set $dict $key $value`. For convenience, it returns the dict,
|
||||
even though the dict was modified in place.
|
||||
- unset: Takes a dict and a key, and deletes that key/value pair from the
|
||||
dict. `unset $dict $key`. This returns the dict for convenience.
|
||||
- hasKey: Takes a dict and a key, and returns boolean true if the key is in
|
||||
the dict.
|
||||
|
||||
Math Functions:
|
||||
|
||||
@@ -179,6 +194,7 @@ import (
|
||||
"math"
|
||||
"math/big"
|
||||
"os"
|
||||
"path"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -363,6 +379,13 @@ var genericMap = map[string]interface{}{
|
||||
"env": func(s string) string { return os.Getenv(s) },
|
||||
"expandenv": func(s string) string { return os.ExpandEnv(s) },
|
||||
|
||||
// File Paths:
|
||||
"base": path.Base,
|
||||
"dir": path.Dir,
|
||||
"clean": path.Clean,
|
||||
"ext": path.Ext,
|
||||
"isAbs": path.IsAbs,
|
||||
|
||||
// Encoding:
|
||||
"b64enc": base64encode,
|
||||
"b64dec": base64decode,
|
||||
@@ -370,8 +393,11 @@ var genericMap = map[string]interface{}{
|
||||
"b32dec": base32decode,
|
||||
|
||||
// Data Structures:
|
||||
"tuple": tuple,
|
||||
"dict": dict,
|
||||
"tuple": tuple,
|
||||
"dict": dict,
|
||||
"set": set,
|
||||
"unset": unset,
|
||||
"hasKey": hasKey,
|
||||
|
||||
// Crypto:
|
||||
"genPrivateKey": generatePrivateKey,
|
||||
@@ -634,6 +660,21 @@ func tuple(v ...interface{}) []interface{} {
|
||||
return v
|
||||
}
|
||||
|
||||
func set(d map[string]interface{}, key string, value interface{}) map[string]interface{} {
|
||||
d[key] = value
|
||||
return d
|
||||
}
|
||||
|
||||
func unset(d map[string]interface{}, key string) map[string]interface{} {
|
||||
delete(d, key)
|
||||
return d
|
||||
}
|
||||
|
||||
func hasKey(d map[string]interface{}, key string) bool {
|
||||
_, ok := d[key]
|
||||
return ok
|
||||
}
|
||||
|
||||
func dict(v ...interface{}) map[string]interface{} {
|
||||
dict := map[string]interface{}{}
|
||||
lenv := len(v)
|
||||
|
69
vendor/github.com/Masterminds/sprig/functions_test.go
generated
vendored
69
vendor/github.com/Masterminds/sprig/functions_test.go
generated
vendored
@@ -12,6 +12,7 @@ import (
|
||||
"text/template"
|
||||
|
||||
"github.com/aokoli/goutils"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
// This is woefully incomplete. Please help.
|
||||
@@ -284,6 +285,16 @@ func TestEmpty(t *testing.T) {
|
||||
if err := runt(tpl, "1"); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
dict := map[string]interface{}{"top": map[string]interface{}{}}
|
||||
tpl = `{{if empty .top.NoSuchThing}}1{{else}}0{{end}}`
|
||||
if err := runtv(tpl, "1", dict); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
tpl = `{{if empty .bottom.NoSuchThing}}1{{else}}0{{end}}`
|
||||
if err := runtv(tpl, "1", dict); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSplit(t *testing.T) {
|
||||
@@ -522,6 +533,43 @@ func TestDict(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnset(t *testing.T) {
|
||||
tpl := `{{- $d := dict "one" 1 "two" 222222 -}}
|
||||
{{- $_ := unset $d "two" -}}
|
||||
{{- range $k, $v := $d}}{{$k}}{{$v}}{{- end -}}
|
||||
`
|
||||
|
||||
expect := "one1"
|
||||
if err := runt(tpl, expect); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
func TestHasKey(t *testing.T) {
|
||||
tpl := `{{- $d := dict "one" 1 "two" 222222 -}}
|
||||
{{- if hasKey $d "one" -}}1{{- end -}}
|
||||
`
|
||||
|
||||
expect := "1"
|
||||
if err := runt(tpl, expect); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSet(t *testing.T) {
|
||||
tpl := `{{- $d := dict "one" 1 "two" 222222 -}}
|
||||
{{- $_ := set $d "two" 2 -}}
|
||||
{{- $_ := set $d "three" 3 -}}
|
||||
{{- if hasKey $d "one" -}}{{$d.one}}{{- end -}}
|
||||
{{- if hasKey $d "two" -}}{{$d.two}}{{- end -}}
|
||||
{{- if hasKey $d "three" -}}{{$d.three}}{{- end -}}
|
||||
`
|
||||
|
||||
expect := "123"
|
||||
if err := runt(tpl, expect); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUntil(t *testing.T) {
|
||||
tests := map[string]string{
|
||||
`{{range $i, $e := until 5}}{{$i}}{{$e}}{{end}}`: "0011223344",
|
||||
@@ -551,6 +599,27 @@ func TestUntilStep(t *testing.T) {
|
||||
|
||||
}
|
||||
|
||||
func TestBase(t *testing.T) {
|
||||
assert.NoError(t, runt(`{{ base "foo/bar" }}`, "bar"))
|
||||
}
|
||||
|
||||
func TestDir(t *testing.T) {
|
||||
assert.NoError(t, runt(`{{ dir "foo/bar/baz" }}`, "foo/bar"))
|
||||
}
|
||||
|
||||
func TestIsAbs(t *testing.T) {
|
||||
assert.NoError(t, runt(`{{ isAbs "/foo" }}`, "true"))
|
||||
assert.NoError(t, runt(`{{ isAbs "foo" }}`, "false"))
|
||||
}
|
||||
|
||||
func TestClean(t *testing.T) {
|
||||
assert.NoError(t, runt(`{{ clean "/foo/../foo/../bar" }}`, "/bar"))
|
||||
}
|
||||
|
||||
func TestExt(t *testing.T) {
|
||||
assert.NoError(t, runt(`{{ ext "/foo/bar/baz.txt" }}`, ".txt"))
|
||||
}
|
||||
|
||||
func TestDelete(t *testing.T) {
|
||||
fmap := TxtFuncMap()
|
||||
delete(fmap, "split")
|
||||
|
Reference in New Issue
Block a user