func (r *rest) Login(ctx context.Context) error { body := &LoginResponse{} iterationIndex, exist := ctx.GetInt("iterationIndex") if !exist { return errors.New("Iteration Index does not exist in context map") } var userList, passList string if _, ok := ctx.GetString("rest:username"); ok { userList, _ = ctx.GetString("rest:username") } else { return errors.New("argument rest:username does not exist") } if _, ok := ctx.GetString("rest:password"); ok { passList, _ = ctx.GetString("rest:password") } else { return errors.New("argument rest:password does not exist") } return checkTargetted(ctx, func(loginEndpoint string, apiEndpoint string) error { return r.PostToUaaSuccessfully(fmt.Sprintf("%s/oauth/token", loginEndpoint), r.oauthInputs(credentialsForWorker(iterationIndex, userList, passList)), body, func(reply Reply) error { ctx.PutString("token", body.Token) return r.targetSpace(ctx) }) }) }
result, exists = localContext.GetString("key2") Ω(result).Should(Equal("123")) Ω(exists).Should(Equal(true)) }) It("can store string value as provided", func() { localContext.PutString("str", "This is a long string \n") result, _ := localContext.GetString("str") Ω(result).Should(Equal("This is a long string \n")) }) It("can store int value as provided", func() { localContext.PutInt("int", 123) result, _ := localContext.GetInt("int") Ω(result).Should(Equal(123)) }) It("can store bool value as provided", func() { localContext.PutBool("key", true) result, _ := localContext.GetBool("key") Ω(result).Should(Equal(true)) }) It("can store float64 value as provided", func() { localContext.PutFloat64("key", float64(3.14)) result, _ := localContext.GetFloat64("key") Ω(result).Should(Equal(float64(3.14)))
worker := NewRedisWorker(conn) result := worker.Time("foo", workloadCtx) Ω(result.Steps[0].Command).Should(Equal("foo")) }) It("Returns any errors", func() { worker := NewRedisWorker(conn) result := worker.Time("stepWithError", workloadCtx) Ω(result.Error).Should(HaveOccurred()) }) It("Passes workload to each step", func() { worker := NewRedisWorker(conn) worker.Time("fooWithContext,barWithContext", workloadCtx) result, exists := workloadCtx.GetInt("a") Ω(exists).Should(Equal(true)) Ω(result).Should(Equal(3)) }) Describe("When multiple steps are provided separated by commas", func() { var result IterationResult JustBeforeEach(func() { worker := NewRedisWorkerWithTimeout(conn, 5) result = worker.Time("foo,bar", workloadCtx) Ω(result.Error).Should(BeNil()) }) It("Reports the total time", func() { Ω(result.Duration.Seconds()).Should(BeNumerically("~", 3, 0.1))