github.com/loafoe/cli@v7.1.0+incompatible/integration/shared/isolated/config_test.go (about) 1 package isolated 2 3 import ( 4 "io/ioutil" 5 "path/filepath" 6 7 helpers "code.cloudfoundry.org/cli/integration/helpers" 8 . "github.com/onsi/ginkgo" 9 . "github.com/onsi/gomega" 10 . "github.com/onsi/gomega/gbytes" 11 . "github.com/onsi/gomega/gexec" 12 ) 13 14 var _ = Describe("Config", func() { 15 var configDir string 16 17 BeforeEach(func() { 18 configDir = filepath.Join(homeDir, ".cf") 19 }) 20 21 Describe("Empty Config File", func() { 22 BeforeEach(func() { 23 helpers.SetConfigContent(configDir, "") 24 }) 25 26 It("displays json warning for a refactored command", func() { 27 session := helpers.CF("api") 28 Eventually(session.Err).Should(Say("Warning: Error read/writing config: unexpected end of JSON input for %s\n", helpers.ConvertPathToRegularExpression(filepath.Join(configDir, "config.json")))) 29 Eventually(session).Should(Exit()) 30 }) 31 32 It("displays json warning for an unrefactored command", func() { 33 session := helpers.CF("curl", "/v2/info") 34 Eventually(session.Err).Should(Say("Warning: Error read/writing config: unexpected end of JSON input for %s\n", helpers.ConvertPathToRegularExpression(filepath.Join(configDir, "config.json")))) 35 Eventually(session).Should(Exit()) 36 }) 37 }) 38 39 Describe("Lingering Config Temp Files", func() { 40 When("lingering tmp files exist from previous failed attempts to write the config", func() { 41 BeforeEach(func() { 42 for i := 0; i < 3; i++ { 43 tmpFile, err := ioutil.TempFile(configDir, "temp-config") 44 Expect(err).ToNot(HaveOccurred()) 45 tmpFile.Close() 46 } 47 }) 48 49 It("removes those temp files on `logout`", func() { 50 Eventually(helpers.CF("logout")).Should(Exit(0)) 51 52 oldTempFileNames, err := filepath.Glob(filepath.Join(configDir, "temp-config?*")) 53 Expect(err).ToNot(HaveOccurred()) 54 Expect(oldTempFileNames).To(BeEmpty()) 55 }) 56 57 It("removes those temp files on `login`", func() { 58 Eventually(helpers.CF("login")).Should(Exit(1)) 59 60 oldTempFileNames, err := filepath.Glob(filepath.Join(configDir, "temp-config?*")) 61 Expect(err).ToNot(HaveOccurred()) 62 Expect(oldTempFileNames).To(BeEmpty()) 63 }) 64 65 It("removes those temp files on `auth`", func() { 66 helpers.LoginCF() 67 68 oldTempFileNames, err := filepath.Glob(filepath.Join(configDir, "temp-config?*")) 69 Expect(err).ToNot(HaveOccurred()) 70 Expect(oldTempFileNames).To(BeEmpty()) 71 }) 72 73 It("removes those temp files on `oauth-token`", func() { 74 Eventually(helpers.CF("oauth-token")).Should(Exit(1)) 75 76 oldTempFileNames, err := filepath.Glob(filepath.Join(configDir, "temp-config?*")) 77 Expect(err).ToNot(HaveOccurred()) 78 Expect(oldTempFileNames).To(BeEmpty()) 79 }) 80 }) 81 }) 82 83 Describe("Enable Color", func() { 84 When("color is enabled", func() { 85 It("prints colors", func() { 86 session := helpers.CFWithEnv(map[string]string{"CF_COLOR": "true"}, "help") 87 Eventually(session).Should(Say("\x1b\\[1m")) 88 Eventually(session).Should(Exit()) 89 }) 90 }) 91 92 When("color is disabled", func() { 93 It("does not print colors", func() { 94 session := helpers.CFWithEnv(map[string]string{"CF_COLOR": "false"}, "help") 95 Consistently(session).ShouldNot(Say("\x1b\\[1m")) 96 Eventually(session).Should(Exit(0)) 97 }) 98 }) 99 }) 100 })