CACert:     "etcd-ca-cert",
						ClientCert: "etcd-client-cert",
						ClientKey:  "etcd-client-key",
						PeerCACert: "etcd-peer-ca-cert",
						PeerCert:   "etcd-peer-cert",
						PeerKey:    "etcd-peer-key",
						ServerCert: "etcd-server-cert",
						ServerKey:  "etcd-server-key",
					},
				},
			}, iaas.NewWardenConfig())
			Expect(err).NotTo(HaveOccurred())

			yaml, err := manifest.ToYAML()
			Expect(err).NotTo(HaveOccurred())
			Expect(yaml).To(gomegamatchers.MatchYAML(etcdManifest))
		})
	})

	Describe("FromYAML", func() {
		It("returns a Manifest matching the given YAML", func() {
			etcdManifest, err := ioutil.ReadFile("fixtures/tls.yml")
			Expect(err).NotTo(HaveOccurred())

			manifest, err := etcd.FromYAML(etcdManifest)
			Expect(err).NotTo(HaveOccurred())

			Expect(manifest.DirectorUUID).To(Equal("some-director-uuid"))
			Expect(manifest.Name).To(Equal("etcd"))
			Expect(manifest.Releases).To(HaveLen(2))
			Expect(manifest.Releases).To(ContainElement(core.Release{
package core_test

import (
	"github.com/pivotal-cf-experimental/destiny/core"
	"github.com/pivotal-cf-experimental/gomegamatchers"

	"gopkg.in/yaml.v2"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Manifest", func() {
	Describe("PropertiesTurbulenceAgentAPI", func() {
		It("serializes the turbulence properties", func() {
			expectedYAML := `host: 1.2.3.4
password: secret
ca_cert: some-cert`
			actualYAML, err := yaml.Marshal(core.PropertiesTurbulenceAgentAPI{
				Host:     "1.2.3.4",
				Password: "******",
				CACert:   "some-cert",
			})

			Expect(err).NotTo(HaveOccurred())
			Expect(actualYAML).To(gomegamatchers.MatchYAML(expectedYAML))
		})
	})
})
Ejemplo n.º 3
0
	})

	AfterEach(func() {
		for name, value := range variables {
			os.Setenv(name, value)
		}
	})

	It("generates a manifest", func() {
		expectedManifest, err := ioutil.ReadFile("fixtures/expected.yml")
		Expect(err).NotTo(HaveOccurred())

		manifest, err := Generate("fixtures/example.yml")
		Expect(err).NotTo(HaveOccurred())

		Expect(manifest).To(gomegamatchers.MatchYAML(expectedManifest))
	})

	Context("failure cases", func() {
		It("returns an error when the parallel nodes is not an int", func() {
			os.Setenv("PARALLEL_NODES", "not an int")
			_, err := Generate("fixtures/example.yml")
			Expect(err).To(MatchError(ContainSubstring(`parsing "not an int": invalid syntax`)))
		})

		It("returns an error when the example manifest does not exist", func() {
			_, err := Generate("fixtures/doesnotexist.yml")
			Expect(err).To(MatchError(ContainSubstring("no such file or directory")))
		})

		It("returns an error when the example manifest is malformed", func() {
					ServerKey:   consul.DC1ServerKey,
					EncryptKeys: []string{consul.EncryptKey},
				},
			}))
		})
	})

	Describe("ToYAML", func() {
		It("returns a YAML representation of the consul manifest", func() {
			consulManifest, err := ioutil.ReadFile("fixtures/consul_manifest.yml")
			Expect(err).NotTo(HaveOccurred())

			manifest, err := consul.NewManifest(consul.Config{
				DirectorUUID: "some-director-uuid",
				Name:         "consul",
				Networks: []consul.ConfigNetwork{
					{
						IPRange: "10.244.4.0/24",
						Nodes:   1,
					},
				},
			}, iaas.NewWardenConfig())
			Expect(err).NotTo(HaveOccurred())

			yaml, err := manifest.ToYAML()
			Expect(err).NotTo(HaveOccurred())
			Expect(yaml).To(gomegamatchers.MatchYAML(consulManifest))
		})
	})
})
					Password:   turbulence.DefaultPassword,
					PrivateKey: turbulence.APIPrivateKey,
				},
			}))
		})
	})

	Describe("ToYAML", func() {
		It("returns a YAML representation of the turbulence manifest", func() {
			turbulenceManifest, err := ioutil.ReadFile("fixtures/turbulence_manifest.yml")
			Expect(err).NotTo(HaveOccurred())

			manifest, err := turbulence.NewManifest(turbulence.Config{
				DirectorUUID: "some-director-uuid",
				Name:         "turbulence",
				IPRange:      "10.244.4.0/24",
				BOSH: turbulence.ConfigBOSH{
					Target:   "some-bosh-target",
					Username: "******",
					Password: "******",
				},
			}, iaas.NewWardenConfig())
			Expect(err).NotTo(HaveOccurred())

			yaml, err := manifest.ToYAML()
			Expect(err).NotTo(HaveOccurred())
			Expect(yaml).To(gomegamatchers.MatchYAML(turbulenceManifest))
		})
	})
})
}

var _ = Describe("MatchYAMLMatcher", func() {
	var animals, plants string

	BeforeEach(func() {
		animals = "- cats:\n  - lion\n- fish:\n  - salmon"
		plants = "- tropical:\n  - palm\n- desert:\n  - cactus"
	})

	Describe("Match", func() {
		It("works with complex yaml", func() {
			yaml, err := ioutil.ReadFile("fixtures/santa_monica_correct.yml")
			Expect(err).NotTo(HaveOccurred())

			isMatch, err := gomegamatchers.MatchYAML(yaml).Match(yaml)
			Expect(err).NotTo(HaveOccurred())
			Expect(isMatch).To(BeTrue())
		})

		Context("when arguments are strings", func() {
			It("returns true when the YAML matches", func() {
				isMatch, err := gomegamatchers.MatchYAML(animals).Match(animals)
				Expect(err).NotTo(HaveOccurred())
				Expect(isMatch).To(BeTrue())
			})

			It("returns false when the YAML does not match", func() {
				isMatch, err := gomegamatchers.MatchYAML(animals).Match(plants)
				Expect(err).NotTo(HaveOccurred())
				Expect(isMatch).To(BeFalse())
		Expect(resolvedManifest).To(gomegamatchers.MatchYAML(`---
director_uuid: some-director-uuid
name: some-name
stemcells:
- alias: default
  name: some-stemcell-name
  version: "2"
instance_groups:
- azs:
  - z1
  instances: 3
  jobs:
  - name: consul_agent
    release: consul
  - name: consul-test-consumer
    release: consul
  name: test_consumer
  networks:
  - name: private
    static_ips:
    - 10.244.4.42
    - 10.244.4.43
    - 10.244.4.44
  stemcell: default
  vm_type: default
properties:
 consul:
   agent:
     datacenter: dc1
     domain: cf.internal
releases:
- name: consul
  version: 2.0.0
- name: consats
  version: 4.0.0
`))