github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+incompatible/cf/commands/config_test.go (about) 1 package commands_test 2 3 import ( 4 "code.cloudfoundry.org/cli/cf/commandregistry" 5 "code.cloudfoundry.org/cli/cf/configuration/coreconfig" 6 "code.cloudfoundry.org/cli/cf/requirements/requirementsfakes" 7 testcmd "code.cloudfoundry.org/cli/util/testhelpers/commands" 8 testconfig "code.cloudfoundry.org/cli/util/testhelpers/configuration" 9 testterm "code.cloudfoundry.org/cli/util/testhelpers/terminal" 10 11 . "code.cloudfoundry.org/cli/util/testhelpers/matchers" 12 . "github.com/onsi/ginkgo" 13 . "github.com/onsi/gomega" 14 ) 15 16 var _ = Describe("config command", func() { 17 var ( 18 ui *testterm.FakeUI 19 configRepo coreconfig.Repository 20 requirementsFactory *requirementsfakes.FakeFactory 21 deps commandregistry.Dependency 22 ) 23 24 updateCommandDependency := func(pluginCall bool) { 25 deps.UI = ui 26 deps.Config = configRepo 27 commandregistry.Commands.SetCommand(commandregistry.Commands.FindCommand("config").SetDependency(deps, pluginCall)) 28 } 29 30 BeforeEach(func() { 31 ui = &testterm.FakeUI{} 32 configRepo = testconfig.NewRepositoryWithDefaults() 33 requirementsFactory = new(requirementsfakes.FakeFactory) 34 }) 35 36 runCommand := func(args ...string) { 37 testcmd.RunCLICommand("config", args, requirementsFactory, updateCommandDependency, false, ui) 38 } 39 It("fails requirements when no flags are provided", func() { 40 runCommand() 41 Expect(ui.Outputs()).To(ContainSubstrings( 42 []string{"Incorrect Usage"}, 43 )) 44 }) 45 46 Context("--async-timeout flag", func() { 47 48 It("stores the timeout in minutes when the --async-timeout flag is provided", func() { 49 runCommand("--async-timeout", "12") 50 Expect(configRepo.AsyncTimeout()).Should(Equal(uint(12))) 51 }) 52 53 It("fails with usage when a invalid async timeout value is passed", func() { 54 runCommand("--async-timeout", "-1") 55 Expect(ui.Outputs()).To(ContainSubstrings( 56 []string{"Incorrect Usage"}, 57 )) 58 }) 59 60 It("fails with usage when a negative timout is passed", func() { 61 runCommand("--async-timeout", "-555") 62 Expect(ui.Outputs()).To(ContainSubstrings( 63 []string{"Incorrect Usage"}, 64 )) 65 Expect(configRepo.AsyncTimeout()).To(Equal(uint(0))) 66 }) 67 }) 68 69 Context("--trace flag", func() { 70 It("stores the trace value when --trace flag is provided", func() { 71 runCommand("--trace", "true") 72 Expect(configRepo.Trace()).Should(Equal("true")) 73 74 runCommand("--trace", "false") 75 Expect(configRepo.Trace()).Should(Equal("false")) 76 77 runCommand("--trace", "some/file/lol") 78 Expect(configRepo.Trace()).Should(Equal("some/file/lol")) 79 }) 80 }) 81 82 Context("--color flag", func() { 83 It("stores the color value when --color flag is provided", func() { 84 runCommand("--color", "true") 85 Expect(configRepo.ColorEnabled()).Should(Equal("true")) 86 87 runCommand("--color", "false") 88 Expect(configRepo.ColorEnabled()).Should(Equal("false")) 89 }) 90 91 It("fails with usage when a non-bool value is provided", func() { 92 runCommand("--color", "plaid") 93 Expect(ui.Outputs()).To(ContainSubstrings( 94 []string{"Incorrect Usage"}, 95 )) 96 }) 97 }) 98 99 Context("--locale flag", func() { 100 It("stores the locale value when --locale [locale] is provided", func() { 101 runCommand("--locale", "zh-Hans") 102 Expect(configRepo.Locale()).Should(Equal("zh-Hans")) 103 }) 104 105 It("informs the user of known locales if an unknown locale is provided", func() { 106 runCommand("--locale", "foo-BAR") 107 Expect(ui.Outputs()).To(ContainSubstrings( 108 []string{"FAILED"}, 109 []string{"Could not find locale 'foo-BAR'. The known locales are:"}, 110 []string{"en-US"}, 111 []string{"fr-FR"}, 112 []string{"zh-Hans"}, 113 )) 114 }) 115 116 Context("when the locale is already set", func() { 117 BeforeEach(func() { 118 configRepo.SetLocale("fr-FR") 119 Expect(configRepo.Locale()).Should(Equal("fr-FR")) 120 }) 121 122 It("clears the locale when the '--locale clear' flag is provided", func() { 123 runCommand("--locale", "CLEAR") 124 Expect(configRepo.Locale()).Should(Equal("")) 125 }) 126 }) 127 }) 128 })