|
6 | 6 | "code.cloudfoundry.org/uaa-cli/config"
|
7 | 7 | . "github.com/onsi/ginkgo"
|
8 | 8 | . "github.com/onsi/gomega"
|
| 9 | + "io/ioutil" |
| 10 | + "os" |
9 | 11 | )
|
10 | 12 |
|
11 | 13 | var _ = Describe("Config", func() {
|
@@ -52,7 +54,41 @@ var _ = Describe("Config", func() {
|
52 | 54 | Expect(cfg2.GetActiveContext().Token.AccessToken).To(Equal("foo-token"))
|
53 | 55 | })
|
54 | 56 |
|
55 |
| - It("places the config file in .uaa in the home directory", func() { |
56 |
| - Expect(config.ConfigPath()).To(HaveSuffix(`/.uaa/config.json`)) |
| 57 | + Context("when UAA_HOME env var is not set", func() { |
| 58 | + It("places the config file in .uaa in the home directory", func() { |
| 59 | + homeDir := os.Getenv("HOME") |
| 60 | + Expect(config.ConfigPath()).To(HavePrefix(homeDir)) |
| 61 | + Expect(config.ConfigPath()).To(HaveSuffix(`/.uaa/config.json`)) |
| 62 | + }) |
| 63 | + }) |
| 64 | + |
| 65 | + Context("when UAA_HOME env var is set", func() { |
| 66 | + var uaaHome string |
| 67 | + |
| 68 | + BeforeEach(func() { |
| 69 | + var err error |
| 70 | + uaaHome, err = ioutil.TempDir(os.TempDir(), "uaa-home") |
| 71 | + Expect(err).ToNot(HaveOccurred()) |
| 72 | + |
| 73 | + err = os.Setenv("UAA_HOME", uaaHome) |
| 74 | + Expect(err).ToNot(HaveOccurred()) |
| 75 | + }) |
| 76 | + |
| 77 | + AfterEach(func() { |
| 78 | + if uaaHome != "" { |
| 79 | + if _, err := os.Stat(uaaHome); !os.IsNotExist(err) { |
| 80 | + err := os.RemoveAll(uaaHome) |
| 81 | + Expect(err).NotTo(HaveOccurred()) |
| 82 | + } |
| 83 | + } |
| 84 | + |
| 85 | + err := os.Unsetenv("UAA_HOME") |
| 86 | + Expect(err).ToNot(HaveOccurred()) |
| 87 | + }) |
| 88 | + |
| 89 | + It("places the config file in the directory pointed to by UAA_HOME", func() { |
| 90 | + Expect(config.ConfigPath()).To(HavePrefix(uaaHome)) |
| 91 | + Expect(config.ConfigPath()).To(HaveSuffix(`config.json`)) |
| 92 | + }) |
57 | 93 | })
|
58 | 94 | })
|
0 commit comments