)

var _ = Describe("TLS key rotation", func() {
	var (
		manifest consul.ManifestV2
		kv       consulclient.HTTPKV
		spammer  *helpers.Spammer
	)

	BeforeEach(func() {
		var err error
		manifest, kv, err = helpers.DeployConsulWithInstanceCount("tls-key-rotation", 3, boshClient, config)
		Expect(err).NotTo(HaveOccurred())

		Eventually(func() ([]bosh.VM, error) {
			return helpers.DeploymentVMs(boshClient, manifest.Name)
		}, "1m", "10s").Should(ConsistOf(helpers.GetVMsFromManifest(manifest)))

		spammer = helpers.NewSpammer(kv, 1*time.Second, "test-consumer-0")
	})

	AfterEach(func() {
		if !CurrentGinkgoTestDescription().Failed {
			err := boshClient.DeleteDeployment(manifest.Name)
			Expect(err).NotTo(HaveOccurred())
		}
	})

	It("successfully rolls with new tls keys and certs", func() {
		By("spamming the kv store", func() {
			spammer.Spam()
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("given large DNS response", func() {
	var (
		consulManifest     consul.ManifestV2
		testConsumerClient testconsumerclient.Client
		err                error
	)
	BeforeEach(func() {
		consulManifest, _, err = helpers.DeployConsulWithFakeDNSServer("large-dns-response", 1, boshClient, config)
		Expect(err).NotTo(HaveOccurred())

		Eventually(func() ([]bosh.VM, error) {
			return helpers.DeploymentVMs(boshClient, consulManifest.Name)
		}, "1m", "10s").Should(ConsistOf(helpers.GetVMsFromManifest(consulManifest)))

		testConsumerClient = testconsumerclient.New(fmt.Sprintf("http://%s:6769", consulManifest.InstanceGroups[1].Networks[0].StaticIPs[0]))
	})

	AfterEach(func() {
		By("deleting consul deployment", func() {
			if !CurrentGinkgoTestDescription().Failed {
				Eventually(func() ([]string, error) {
					return lockedDeployments()
				}, "10m", "30s").ShouldNot(ContainElement(consulManifest.Name))

				err := boshClient.DeleteDeployment(consulManifest.Name)
				Expect(err).NotTo(HaveOccurred())
			}