|
7 | 7 | "io/ioutil"
|
8 | 8 | "os"
|
9 | 9 | "path"
|
| 10 | + "path/filepath" |
10 | 11 | "testing"
|
11 | 12 |
|
12 | 13 | "github.com/docker/docker/client"
|
@@ -65,24 +66,14 @@ var _ = Describe("ship update", func() {
|
65 | 66 | testOutputPath, err = ioutil.TempDir(testPath, "_test_")
|
66 | 67 | Expect(err).NotTo(HaveOccurred())
|
67 | 68 |
|
68 |
| - // create `/test/.ship/state.json` and copy in the input state file before the test runs |
69 |
| - err := os.Mkdir(path.Join(testOutputPath, ".ship"), 0777) |
70 |
| - Expect(err).NotTo(HaveOccurred()) |
71 |
| - outputStateFile := path.Join(testOutputPath, ".ship/state.json") |
72 |
| - |
73 |
| - // read .ship/state.json from input state file |
74 |
| - stateFile, err := ioutil.ReadFile(path.Join(testInputPath, ".ship/state.json")) |
75 |
| - Expect(err).NotTo(HaveOccurred()) |
| 69 | + recursiveCopy(testInputPath, testOutputPath) |
76 | 70 |
|
77 | 71 | // the test needs to execute in the same directory throughout the lifecycle of `ship update`
|
78 | 72 | testInputPath = testOutputPath
|
79 | 73 |
|
80 |
| - // copy .ship/state.json from testInputPath to testOutputPath |
81 |
| - err = ioutil.WriteFile(outputStateFile, stateFile, 0777) |
| 74 | + err = os.Chdir(testOutputPath) |
82 | 75 | Expect(err).NotTo(HaveOccurred())
|
83 | 76 |
|
84 |
| - os.Chdir(testOutputPath) |
85 |
| - |
86 | 77 | // read the test metadata
|
87 | 78 | testMetadata = readMetadata(testPath)
|
88 | 79 | }, 20)
|
@@ -151,3 +142,22 @@ func readMetadata(testPath string) TestMetadata {
|
151 | 142 |
|
152 | 143 | return testMetadata
|
153 | 144 | }
|
| 145 | + |
| 146 | +func recursiveCopy(sourceDir, destDir string) { |
| 147 | + err := os.MkdirAll(destDir, os.ModePerm) |
| 148 | + Expect(err).NotTo(HaveOccurred()) |
| 149 | + srcFiles, err := ioutil.ReadDir(sourceDir) |
| 150 | + Expect(err).NotTo(HaveOccurred()) |
| 151 | + for _, file := range srcFiles { |
| 152 | + if file.IsDir() { |
| 153 | + recursiveCopy(filepath.Join(sourceDir, file.Name()), filepath.Join(destDir, file.Name())) |
| 154 | + } else { |
| 155 | + // is file |
| 156 | + contents, err := ioutil.ReadFile(filepath.Join(sourceDir, file.Name())) |
| 157 | + Expect(err).NotTo(HaveOccurred()) |
| 158 | + |
| 159 | + err = ioutil.WriteFile(filepath.Join(destDir, file.Name()), contents, file.Mode()) |
| 160 | + Expect(err).NotTo(HaveOccurred()) |
| 161 | + } |
| 162 | + } |
| 163 | +} |
0 commit comments