test(template,terminal): drop tests that assert implementation details

TestRestrictedFuncMapExactKeySet pinned a 190-entry hardcoded list that
just mirrors the map's own construction data; the drift-guard and
dangerous-funcs-excluded tests already cover the real invariants, so it
only added maintenance burden without extra protection.

TestStripControlRunesFastPath asserted unsafe.StringData pointer
identity to prove the no-allocation path ran — a memory-layout detail,
not behavior. The unchanged-input case is already covered functionally
by TestStripControlRunes's unicode case.
This commit is contained in:
Jan De Dobbeleer
2026-08-01 15:55:08 +02:00
committed by Jan De Dobbeleer
parent 7bfd50b858
commit db6ea0effc
2 changed files with 0 additions and 55 deletions
-45
View File
@@ -1,12 +1,9 @@
package template
import (
"sort"
"testing"
"github.com/Masterminds/sprig/v3"
"github.com/stretchr/testify/assert"
)
// TestRestrictedAllowedSprigFuncsCoversAllSprigFuncs is the drift guard: a
@@ -32,45 +29,3 @@ func TestRestrictedAllowedSprigFuncsCoversAllSprigFuncs(t *testing.T) {
"or heavy-CPU work, or to restrictedAllowedSprigFuncs if it's confirmed safe for untrusted input", name)
}
}
// TestRestrictedFuncMapExactKeySet pins the exact set of functions exposed to
// untrusted templates for the current sprig version, guarding against
// accidental behavior changes to restrictedFuncMap.
func TestRestrictedFuncMapExactKeySet(t *testing.T) {
expected := []string{
"abbrev", "abbrevboth", "add", "add1", "add1f", "addf", "adler32sum", "ago", "all", "any", "append", "atoi",
"b32dec", "b32enc", "b64dec", "b64enc", "base", "biggest", "camelcase", "cat", "ceil", "chunk", "clean",
"coalesce", "compact", "concat", "contains", "date", "dateInZone", "dateModify", "date_in_zone", "date_modify",
"deepCopy", "deepEqual", "default", "dict", "dig", "dir", "div", "divf", "duration", "durationRound", "empty",
"ext", "fail", "findP", "first", "float64", "floor", "fromJson", "get", "gt", "has", "hasKey", "hasPrefix",
"hasSuffix", "hello", "hresult", "htmlDate", "htmlDateInZone", "indent", "initial", "initials", "int", "int64",
"isAbs", "join", "kebabcase", "keys", "kindIs", "kindOf", "last", "list", "localeShortDate", "localeShortTime",
"lower", "lt", "matchP", "max", "maxf", "merge", "mergeOverwrite", "min", "minf", "mod", "mul", "mulf",
"mustAppend", "mustChunk", "mustCompact", "mustDateModify", "mustDeepCopy", "mustFirst", "mustFromJson",
"mustHas", "mustInitial", "mustLast", "mustMerge", "mustMergeOverwrite", "mustPrepend", "mustPush",
"mustRegexFind", "mustRegexFindAll", "mustRegexMatch", "mustRegexReplaceAll", "mustRegexReplaceAllLiteral",
"mustRegexSplit", "mustRest", "mustReverse", "mustSlice", "mustToDate", "mustToJson", "mustToPrettyJson",
"mustToRawJson", "mustUniq", "mustWithout", "must_date_modify", "nindent", "nospace", "now", "omit", "osBase",
"osClean", "osDir", "osExt", "osIsAbs", "path", "pick", "pluck", "plural", "prepend", "push", "quote",
"randAlpha", "randAlphaNum", "randAscii", "randInt", "randNumeric", "random", "reason", "regexFind",
"regexFindAll", "regexMatch", "regexQuoteMeta", "regexReplaceAll", "regexReplaceAllLiteral", "regexSplit",
"repeat", "replace", "replaceP", "rest", "reverse", "round", "secondsRound", "semver", "semverCompare", "seq",
"set", "sha1sum", "sha256sum", "sha512sum", "shuffle", "slice", "snakecase", "sortAlpha", "split", "splitList",
"splitn", "squote", "sub", "subf", "substr", "swapcase", "ternary", "title", "toDate", "toDecimal", "toJson",
"toPrettyJson", "toRawJson", "toString", "toStrings", "trim", "trimAll", "trimPrefix", "trimSuffix", "trimall",
"trunc", "truncE", "tuple", "typeIs", "typeIsLike", "typeOf", "uniq", "unixEpoch", "unset", "until", "untilStep",
"untitle", "upper", "url", "urlJoin", "urlParse", "uuidv4", "values", "without", "wrap", "wrapWith",
}
fm := funcMap(false)
actual := make([]string, 0, len(fm))
for key := range fm {
actual = append(actual, key)
}
sort.Strings(actual)
sort.Strings(expected)
assert.Equal(t, expected, actual)
}
-10
View File
@@ -2,7 +2,6 @@ package terminal
import (
"testing"
"unsafe"
"github.com/jandedobbeleer/oh-my-posh/src/color"
"github.com/jandedobbeleer/oh-my-posh/src/shell"
@@ -600,12 +599,3 @@ func TestStripControlRunes(t *testing.T) {
})
}
}
func TestStripControlRunesFastPath(t *testing.T) {
input := "no control runes here, just plain text"
got := stripControlRunes(input)
assert.Equal(t, input, got)
assert.Same(t, unsafe.StringData(input), unsafe.StringData(got), "fast path must return the input unchanged, not a copy")
}