func (cmd targetCommand) Execute(args []string) (int, error) { cmd.printer.Printf("Executing %s comamnd: args: %#v, options: %#v", cmd.Name(), args, cmd.options) validate, err := cmd.Validate() if validate == false && err == nil { return 1, errors.New("bmp target validation error") } else if validate == false && err != nil { return 1, err } configInfo, err := common.CreateConfig(cmd.bmpClient.ConfigPath()) if err != nil { return 1, err } configInfo.TargetUrl = cmd.options.Target c := config.NewConfig(cmd.bmpClient.ConfigPath()) err = c.SaveConfig(configInfo) if err != nil { return 1, err } return 0, nil }
fakeBmpClient = clientsfakes.NewFakeBmpClient(options.Username, options.Password, "http://fake.target.url", tmpFileName) fakeBmpClient.LoginResponse.Status = 200 fakeBmpClient.LoginErr = nil cmd = bmp.NewLoginCommand(options, fakeBmpClient) }) It("executes with no error", func() { rc, err := cmd.Execute(args) Expect(rc).To(Equal(0)) Expect(err).ToNot(HaveOccurred()) }) It("saves the Username and Password to Config", func() { configInfo, err := common.CreateConfig(fakeBmpClient.ConfigPath()) Expect(err).ToNot(HaveOccurred()) Expect(configInfo.Username).To(Equal("")) Expect(configInfo.Password).To(Equal("")) Expect(configInfo.TargetUrl).To(Equal("")) rc, err := cmd.Execute(args) Expect(rc).To(Equal(0)) Expect(err).ToNot(HaveOccurred()) c := config.NewConfig(fakeBmpClient.ConfigPath()) Expect(err).ToNot(HaveOccurred()) configInfo, err = c.LoadConfig() Expect(err).ToNot(HaveOccurred())