Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const (
IMPLICIT = GrantType("implicit")
PASSWORD = GrantType("password")
CLIENT_CREDENTIALS = GrantType("client_credentials")
UAA_HOME_ENV_VAR = "UAA_HOME"
)

type Config struct {
Expand Down Expand Up @@ -110,6 +111,10 @@ func (uc UaaContext) name() string {
}

func ConfigDir() string {
if path, found := os.LookupEnv(UAA_HOME_ENV_VAR); found {
return path
}

return path.Join(userHomeDir(), ".uaa")
}

Expand Down
40 changes: 38 additions & 2 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"code.cloudfoundry.org/uaa-cli/config"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"io/ioutil"
"os"
)

var _ = Describe("Config", func() {
Expand Down Expand Up @@ -52,7 +54,41 @@ var _ = Describe("Config", func() {
Expect(cfg2.GetActiveContext().Token.AccessToken).To(Equal("foo-token"))
})

It("places the config file in .uaa in the home directory", func() {
Expect(config.ConfigPath()).To(HaveSuffix(`/.uaa/config.json`))
Context("when UAA_HOME env var is not set", func() {
It("places the config file in .uaa in the home directory", func() {
homeDir := os.Getenv("HOME")
Expect(config.ConfigPath()).To(HavePrefix(homeDir))
Expect(config.ConfigPath()).To(HaveSuffix(`/.uaa/config.json`))
})
})

Context("when UAA_HOME env var is set", func() {
var uaaHome string

BeforeEach(func() {
var err error
uaaHome, err = ioutil.TempDir(os.TempDir(), "uaa-home")
Expect(err).ToNot(HaveOccurred())

err = os.Setenv("UAA_HOME", uaaHome)
Expect(err).ToNot(HaveOccurred())
})

AfterEach(func() {
if uaaHome != "" {
if _, err := os.Stat(uaaHome); !os.IsNotExist(err) {
err := os.RemoveAll(uaaHome)
Expect(err).NotTo(HaveOccurred())
}
}

err := os.Unsetenv("UAA_HOME")
Expect(err).ToNot(HaveOccurred())
})

It("places the config file in the directory pointed to by UAA_HOME", func() {
Expect(config.ConfigPath()).To(HavePrefix(uaaHome))
Expect(config.ConfigPath()).To(HaveSuffix(`config.json`))
})
})
})