MCPcopy Create free account
hub / github.com/devspace-sh/devspace / TestWalk

Function TestWalk

pkg/devspace/deploy/deployer/kubectl/walk/walk_test.go:10–60  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

8)
9
10func TestWalk(t *testing.T) {
11
12 // Input yaml
13 input := `
14test:
15 image: appendtag
16 test: []
17test2:
18 image: dontreplaceme
19 test3:
20 - test4:
21 test5:
22 image: replaceme
23`
24 inputObj := make(map[string]interface{})
25 err := yaml.Unmarshal([]byte(input), inputObj)
26 if err != nil {
27 t.Fatalf("Error parsing input: %v", err)
28 }
29
30 match := MatchFn(func(key, value string) bool {
31 return key == "image" && value != "dontreplaceme"
32 })
33 replace := ReplaceFn(func(_, value string) (interface{}, error) {
34 if value == "appendtag" {
35 return "appendtag:test", nil
36 }
37
38 return "replaced", nil
39 })
40
41 _ = Walk(inputObj, match, replace)
42
43 output, err := yaml.Marshal(inputObj)
44 if err != nil {
45 t.Fatalf("Error parsing output: %v", err)
46 }
47
48 // Output yaml
49 expected := `test:
50 image: appendtag:test
51 test: []
52test2:
53 image: dontreplaceme
54 test3:
55 - test4:
56 image: replaced
57 test5: null
58`
59 assert.Equal(t, string(output), expected)
60}

Callers

nothing calls this directly

Calls 5

MatchFnFuncType · 0.85
ReplaceFnFuncType · 0.85
WalkFunction · 0.85
EqualMethod · 0.80
FatalfMethod · 0.45

Tested by

no test coverage detected