...
1
2
3
4 package frameworktestutil
5
6 import (
7 "path/filepath"
8 "testing"
9
10 "github.com/spf13/cobra"
11 "github.com/stretchr/testify/require"
12 "sigs.k8s.io/kustomize/kyaml/fn/framework"
13 "sigs.k8s.io/kustomize/kyaml/fn/framework/command"
14 "sigs.k8s.io/kustomize/kyaml/kio"
15 "sigs.k8s.io/kustomize/kyaml/yaml"
16 )
17
18 func TestProcessorResultsChecker_UpdateExpectedFromActual(t *testing.T) {
19 dir := filepath.FromSlash("testdata/update_expectations/processor")
20 checker := ProcessorResultsChecker{
21 TestDataDirectory: dir,
22 UpdateExpectedFromActual: true,
23 Processor: testProcessor,
24 }
25
26 checker.Assert(t)
27 require.Contains(t, checker.TestCasesRun(), filepath.Join(dir, "important_subdir"))
28
29 checker.UpdateExpectedFromActual = false
30
31 checker.Assert(t)
32 require.Contains(t, checker.TestCasesRun(), filepath.Join(dir, "important_subdir"))
33 }
34
35 func TestCommandResultsChecker_UpdateExpectedFromActual(t *testing.T) {
36 dir := filepath.FromSlash("testdata/update_expectations/command")
37 checker := CommandResultsChecker{
38 TestDataDirectory: dir,
39 UpdateExpectedFromActual: true,
40 Command: testCommand,
41 }
42
43 checker.Assert(t)
44 require.Contains(t, checker.TestCasesRun(), filepath.Join(dir, "important_subdir"))
45
46 checker.UpdateExpectedFromActual = false
47
48 checker.Assert(t)
49 require.Contains(t, checker.TestCasesRun(), filepath.Join(dir, "important_subdir"))
50 }
51
52 func testCommand() *cobra.Command {
53 return command.Build(testProcessor(), command.StandaloneEnabled, false)
54 }
55
56 func testProcessor() framework.ResourceListProcessor {
57 return framework.SimpleProcessor{
58 Filter: kio.FilterFunc(func(nodes []*yaml.RNode) ([]*yaml.RNode, error) {
59 for _, node := range nodes {
60 err := node.SetAnnotations(map[string]string{"updated": "true"})
61 if err != nil {
62 return nil, err
63 }
64 }
65 return nodes, nil
66 }),
67 }
68 }
69
View as plain text