MCPcopy Create free account
hub / github.com/devfile/api / TestMerging

Function TestMerging

pkg/utils/overriding/merging_test.go:45–97  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

43}
44
45func TestMerging(t *testing.T) {
46 filepath.Walk("test-fixtures/merges", func(path string, info os.FileInfo, err error) error {
47 if !info.IsDir() && info.Name() == "main.yaml" {
48 if err != nil {
49 t.Error(err)
50 return nil
51 }
52 main, err := ioutil.ReadFile(path)
53 if err != nil {
54 t.Error(err)
55 return nil
56 }
57 dirPath := filepath.Dir(path)
58 parent := []byte{}
59 parentFile := filepath.Join(dirPath, "parent.yaml")
60 if _, err = os.Stat(parentFile); err == nil {
61 parent, err = ioutil.ReadFile(parentFile)
62 if err != nil {
63 t.Error(err)
64 return nil
65 }
66 }
67
68 plugins := [][]byte{}
69 pluginFile := filepath.Join(dirPath, "plugin.yaml")
70 if _, err = os.Stat(pluginFile); err == nil {
71 plugin, err := ioutil.ReadFile(filepath.Join(dirPath, "plugin.yaml"))
72 if err != nil {
73 t.Error(err)
74 return nil
75 }
76 plugins = append(plugins, plugin)
77 }
78 var resultTemplate dw.DevWorkspaceTemplateSpecContent
79 resultError := ""
80 errorFile := filepath.Join(dirPath, "result-error.txt")
81 if _, err = os.Stat(errorFile); err == nil {
82 resultErrorBytes, err := ioutil.ReadFile(errorFile)
83 if err != nil {
84 t.Error(err)
85 return nil
86 }
87 resultError = string(resultErrorBytes)
88 } else {
89 readFileToStruct(t, filepath.Join(dirPath, "result.yaml"), &resultTemplate)
90 }
91 testName := filepath.Base(dirPath)
92
93 t.Run(testName, mergingPatchTest(main, parent, resultTemplate, resultError, plugins...))
94 }
95 return nil
96 })
97}
98
99func TestMergingOnlyPlugins(t *testing.T) {
100 baseFile := "test-fixtures/merges/no-parent/main.yaml"

Callers

nothing calls this directly

Calls 4

mergingPatchTestFunction · 0.85
NameMethod · 0.80
readFileToStructFunction · 0.70
ErrorMethod · 0.45

Tested by

no test coverage detected