MCPcopy
hub / github.com/go-task/task / TestVars_ToCacheMap

Function TestVars_ToCacheMap

taskfile/ast/vars_test.go:9–55  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

7)
8
9func TestVars_ToCacheMap(t *testing.T) {
10 t.Parallel()
11
12 t.Run("nil receiver returns nil", func(t *testing.T) {
13 t.Parallel()
14 var vars *Vars
15 assert.Nil(t, vars.ToCacheMap())
16 })
17
18 t.Run("empty vars returns empty map", func(t *testing.T) {
19 t.Parallel()
20 vars := NewVars()
21 m := vars.ToCacheMap()
22 assert.NotNil(t, m)
23 assert.Empty(t, m)
24 })
25
26 t.Run("static values are included", func(t *testing.T) {
27 t.Parallel()
28 vars := NewVars(
29 &VarElement{Key: "FOO", Value: Var{Value: "bar"}},
30 &VarElement{Key: "NUM", Value: Var{Value: 42}},
31 )
32 m := vars.ToCacheMap()
33 assert.Equal(t, map[string]any{"FOO": "bar", "NUM": 42}, m)
34 })
35
36 t.Run("live values take precedence over static values", func(t *testing.T) {
37 t.Parallel()
38 vars := NewVars(
39 &VarElement{Key: "FOO", Value: Var{Value: "bar", Live: "live-bar"}},
40 )
41 m := vars.ToCacheMap()
42 assert.Equal(t, map[string]any{"FOO": "live-bar"}, m)
43 })
44
45 t.Run("dynamic variables are excluded", func(t *testing.T) {
46 t.Parallel()
47 sh := "echo hello"
48 vars := NewVars(
49 &VarElement{Key: "STATIC", Value: Var{Value: "ok"}},
50 &VarElement{Key: "DYNAMIC", Value: Var{Sh: &sh}},
51 )
52 m := vars.ToCacheMap()
53 assert.Equal(t, map[string]any{"STATIC": "ok"}, m)
54 })
55}

Callers

nothing calls this directly

Calls 3

ToCacheMapMethod · 0.95
NewVarsFunction · 0.85
RunMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…