github.com/orange-cloudfoundry/cli@v7.1.0+incompatible/command/v7/config_command_test.go (about) 1 package v7_test 2 3 import ( 4 "code.cloudfoundry.org/cli/command/commandfakes" 5 "code.cloudfoundry.org/cli/command/flag" 6 "code.cloudfoundry.org/cli/command/translatableerror" 7 . "code.cloudfoundry.org/cli/command/v7" 8 v7 "code.cloudfoundry.org/cli/command/v7" 9 "code.cloudfoundry.org/cli/types" 10 "code.cloudfoundry.org/cli/util/ui" 11 . "github.com/onsi/ginkgo" 12 . "github.com/onsi/gomega" 13 . "github.com/onsi/gomega/gbytes" 14 ) 15 16 var _ = Describe("ConfigCommand", func() { 17 var ( 18 cmd v7.ConfigCommand 19 testUI *ui.UI 20 fakeConfig *commandfakes.FakeConfig 21 executeErr error 22 ) 23 24 BeforeEach(func() { 25 testUI = ui.NewTestUI(nil, NewBuffer(), NewBuffer()) 26 fakeConfig = new(commandfakes.FakeConfig) 27 28 cmd = ConfigCommand{ 29 UI: testUI, 30 Config: fakeConfig, 31 } 32 }) 33 34 JustBeforeEach(func() { 35 executeErr = cmd.Execute(nil) 36 }) 37 38 When("there are no flags given", func() { 39 It("returns an error", func() { 40 Expect(executeErr).To(MatchError( 41 translatableerror.IncorrectUsageError{Message: "at least one flag must be provided"}, 42 )) 43 }) 44 }) 45 46 When("using the async timeout flag", func() { 47 BeforeEach(func() { 48 cmd.AsyncTimeout = flag.Timeout{NullInt: types.NullInt{IsSet: true, Value: 2}} 49 }) 50 51 It("successfully updates the config", func() { 52 Expect(executeErr).To(Not(HaveOccurred())) 53 Expect(fakeConfig.SetAsyncTimeoutCallCount()).To(Equal(1)) 54 value := fakeConfig.SetAsyncTimeoutArgsForCall(0) 55 Expect(value).To(Equal(2)) 56 }) 57 }) 58 59 When("using the color flag", func() { 60 BeforeEach(func() { 61 cmd.Color = flag.Color{IsSet: true, Value: "true"} 62 }) 63 64 It("successfully updates the config", func() { 65 Expect(executeErr).To(Not(HaveOccurred())) 66 Expect(fakeConfig.SetColorEnabledCallCount()).To(Equal(1)) 67 value := fakeConfig.SetColorEnabledArgsForCall(0) 68 Expect(value).To(Equal("true")) 69 }) 70 }) 71 72 When("using the locale flag", func() { 73 BeforeEach(func() { 74 cmd.Locale = flag.Locale{Locale: "en-US"} 75 }) 76 77 It("successfully updates the config", func() { 78 Expect(executeErr).To(Not(HaveOccurred())) 79 Expect(fakeConfig.SetLocaleCallCount()).To(Equal(1)) 80 value := fakeConfig.SetLocaleArgsForCall(0) 81 Expect(value).To(Equal("en-US")) 82 }) 83 }) 84 85 When("using the trace flag", func() { 86 BeforeEach(func() { 87 cmd.Trace = "my-trace-file" 88 }) 89 90 It("successfully updates the config", func() { 91 Expect(executeErr).To(Not(HaveOccurred())) 92 Expect(fakeConfig.SetTraceCallCount()).To(Equal(1)) 93 value := fakeConfig.SetTraceArgsForCall(0) 94 Expect(value).To(Equal("my-trace-file")) 95 }) 96 }) 97 })