|
5 | 5 | "io/ioutil"
|
6 | 6 | "os"
|
7 | 7 | "path/filepath"
|
| 8 | + "time" |
8 | 9 |
|
9 | 10 | "code.cloudfoundry.org/cli/command/translatableerror"
|
10 | 11 | "code.cloudfoundry.org/cli/integration/helpers"
|
@@ -60,22 +61,48 @@ var _ = Describe("Config", func() {
|
60 | 61 | })
|
61 | 62 |
|
62 | 63 | When("there are old temp-config* files lingering from previous failed attempts to write the config", func() {
|
63 |
| - BeforeEach(func() { |
64 |
| - configDir := filepath.Join(homeDir, ".cf") |
65 |
| - Expect(os.MkdirAll(configDir, 0777)).To(Succeed()) |
66 |
| - for i := 0; i < 3; i++ { |
67 |
| - tmpFile, fileErr := ioutil.TempFile(configDir, "temp-config") |
68 |
| - Expect(fileErr).ToNot(HaveOccurred()) |
69 |
| - tmpFile.Close() |
70 |
| - } |
| 64 | + Context("and the files are younger than 5 minutes", func() { |
| 65 | + BeforeEach(func() { |
| 66 | + configDir := filepath.Join(homeDir, ".cf") |
| 67 | + Expect(os.MkdirAll(configDir, 0777)).To(Succeed()) |
| 68 | + for i := 0; i < 3; i++ { |
| 69 | + configDir := filepath.Join(homeDir, ".cf") |
| 70 | + tmpFile, fileErr := ioutil.TempFile(configDir, "temp-config") |
| 71 | + Expect(fileErr).ToNot(HaveOccurred()) |
| 72 | + tmpFile.Close() |
| 73 | + } |
| 74 | + }) |
| 75 | + |
| 76 | + It("keeps the files", func() { |
| 77 | + Expect(loadErr).ToNot(HaveOccurred()) |
| 78 | + |
| 79 | + oldTempFileNames, configErr := filepath.Glob(filepath.Join(homeDir, ".cf", "temp-config?*")) |
| 80 | + Expect(configErr).ToNot(HaveOccurred()) |
| 81 | + Expect(oldTempFileNames).To(HaveLen(3)) |
| 82 | + }) |
71 | 83 | })
|
72 | 84 |
|
73 |
| - It("removes the lingering temp-config* files", func() { |
74 |
| - Expect(loadErr).ToNot(HaveOccurred()) |
| 85 | + Context("and the files are older than 5 minutes", func() { |
| 86 | + BeforeEach(func() { |
| 87 | + configDir := filepath.Join(homeDir, ".cf") |
| 88 | + Expect(os.MkdirAll(configDir, 0777)).To(Succeed()) |
| 89 | + for i := 0; i < 3; i++ { |
| 90 | + tmpFile, fileErr := ioutil.TempFile(configDir, "temp-config") |
| 91 | + Expect(fileErr).ToNot(HaveOccurred()) |
| 92 | + tmpFile.Close() |
| 93 | + oldTime := time.Now().Add(-time.Minute * 10) |
| 94 | + err := os.Chtimes(tmpFile.Name(), oldTime, oldTime) |
| 95 | + Expect(err).ToNot(HaveOccurred()) |
| 96 | + } |
| 97 | + }) |
75 | 98 |
|
76 |
| - oldTempFileNames, configErr := filepath.Glob(filepath.Join(homeDir, ".cf", "temp-config?*")) |
77 |
| - Expect(configErr).ToNot(HaveOccurred()) |
78 |
| - Expect(oldTempFileNames).To(BeEmpty()) |
| 99 | + It("removes the lingering temp-config* files", func() { |
| 100 | + Expect(loadErr).ToNot(HaveOccurred()) |
| 101 | + |
| 102 | + oldTempFileNames, configErr := filepath.Glob(filepath.Join(homeDir, ".cf", "temp-config?*")) |
| 103 | + Expect(configErr).ToNot(HaveOccurred()) |
| 104 | + Expect(oldTempFileNames).To(BeEmpty()) |
| 105 | + }) |
79 | 106 | })
|
80 | 107 | })
|
81 | 108 |
|
|
0 commit comments