MCPcopy Index your code
hub / github.com/devspace-sh/devspace / compareFiles

Function compareFiles

helper/server/upstream_test.go:74–118  ·  view source on GitHub ↗
(dir string, file testFile)

Source from the content-addressed store, hash-verified

72}
73
74func compareFiles(dir string, file testFile) error {
75 files, err := os.ReadDir(dir)
76 if err != nil {
77 return err
78 }
79 if len(file.Children) != len(files) {
80 return errors.Errorf("dir %s expected %d children, got %d", dir, len(file.Children), len(files))
81 }
82
83 // check
84 for childName, child := range file.Children {
85 found := false
86 for _, f := range files {
87 if f.Name() == childName {
88 if f.IsDir() != (child.Children != nil) {
89 return errors.Errorf("child %s in dir %s: real isDir %v != expected isDir %v", childName, dir, f.IsDir(), child.Children != nil)
90 }
91 if child.Data != nil {
92 data, err := os.ReadFile(filepath.Join(dir, f.Name()))
93 if err != nil {
94 return err
95 }
96 if string(data) != string(child.Data) {
97 return errors.Errorf("child %s in dir %s: expected data %s, got %s", childName, dir, string(child.Data), string(data))
98 }
99 }
100 if child.Children != nil {
101 err := compareFiles(filepath.Join(dir, childName), child)
102 if err != nil {
103 return err
104 }
105 }
106
107 found = true
108 break
109 }
110 }
111
112 if found == false {
113 return errors.Errorf("dir %s: path %s not found", dir, childName)
114 }
115 }
116
117 return nil
118}
119
120func createFiles(dir string, file testFile) error {
121 for name, child := range file.Children {

Callers 2

TestUpstreamServerFunction · 0.85
TestDownstreamServerFunction · 0.85

Calls 3

NameMethod · 0.65
ErrorfMethod · 0.45
IsDirMethod · 0.45

Tested by

no test coverage detected