Expect(client.SetKeys([]string{"key1"})).To(MatchError("install key error"))
				})
			})

			Context("when UseKey returns an error", func() {
				It("returns the error", func() {
					consulRPCClient.UseKeyReturns(errors.New("use key error"))

					Expect(client.SetKeys([]string{"key1"})).To(MatchError("use key error"))
				})
			})
		})
	})

	Describe("Leave", func() {
		It("leaves the cluster", func() {
			Expect(client.Leave()).To(Succeed())
			Expect(consulRPCClient.LeaveCallCount()).To(Equal(1))
		})

		Context("when RPCClient.leave returns an error", func() {
			It("returns an error", func() {
				consulRPCClient.LeaveReturns(errors.New("leave error"))

				Expect(client.Leave()).To(MatchError("leave error"))
				Expect(consulRPCClient.LeaveCallCount()).To(Equal(1))
			})
		})
	})
})
						{
							Action: "agent-client.set-keys.use-key.request.failed",
							Error:  errors.New("use key error"),
							Data: []lager.Data{{
								"key": encryptedKey1,
							}},
						},
					}))
				})
			})
		})
	})

	Describe("Leave", func() {
		It("leaves the cluster", func() {
			Expect(client.Leave()).To(Succeed())
			Expect(consulRPCClient.LeaveCallCount()).To(Equal(1))
			Expect(logger.Messages).To(ContainSequence([]fakes.LoggerMessage{
				{
					Action: "agent-client.leave.leave.request",
				},
				{
					Action: "agent-client.leave.leave.response",
				},
			}))
		})

		Context("when RPCClient.leave returns an error", func() {
			It("returns an error", func() {
				consulRPCClient.LeaveReturns(errors.New("leave error"))