(dir string, file testFile)
| 72 | } |
| 73 | |
| 74 | func 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 | |
| 120 | func createFiles(dir string, file testFile) error { |
| 121 | for name, child := range file.Children { |
no test coverage detected