<commit_before><commit_msg>Add vsphere CPI tests<commit_after>package boshinit_test

import (
	"github.com/enaml-ops/enaml"
	. "github.com/enaml-ops/omg-cli/deployments/bosh-init"
	"github.com/enaml-ops/omg-cli/deployments/bosh-init/enaml-gen/vsphere_cpi"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("NewVSphereBosh", func() {
	Describe("given the function", func() {
		Context("when called w/ valid parameters", func() {
			var boshConfig = BoshInitConfig{
				Name:                              "bosh",
				BoshReleaseVersion:                "256.2",
				BoshPrivateIP:                     "172.16.1.6",
				BoshCPIReleaseVersion:             "22",
				GoAgentVersion:                    "3232.4",
				BoshReleaseSHA:                    "ff2f4e16e02f66b31c595196052a809100cfd5a8",
				BoshCPIReleaseSHA:                 "dd1827e5f4dfc37656017c9f6e48441f51a7ab73",
				GoAgentSHA:                        "27ec32ddbdea13e3025700206388ae5882a23c67",
				BoshDirectorName:                  "my-bosh",
				VSphereAddress:                    "172.16.1.2",
				VSphereUser:                       "vsadmin",
				VSpherePassword:                   "<PASSWORD>",
				VSphereDatacenterName:             "PCF_DC1",
				VSphereVMFolder:                   "pcf_vms",
				VSphereTemplateFolder:             "pcf_templates",
				VSphereDatastorePattern:           "DS1",
				VSpherePersistentDatastorePattern: "DS1_Persistent",
				VSphereDiskPath:                   "pcf_disks",
				VSphereClusters:                   []string{"PCF1"},
				VSphereNetworks: []Network{Network{
					Name:    "PCF_Net1",
					Range:   "172.16.0.0/23",
					Gateway: "172.16.1.1",
					DNS:     []string{"172.16.1.2"},
				}},
			}
			var manifest *enaml.DeploymentManifest

			BeforeEach(func() {
				manifest = NewVSphereBosh(boshConfig)
			})

			It("then it should be using the vsphere esx stemcell", func() {
				Ω(manifest.ResourcePools[0].Stemcell.URL).ShouldNot(ContainSubstring("aws"))
				Ω(manifest.ResourcePools[0].Stemcell.URL).ShouldNot(ContainSubstring("azure"))
				Ω(manifest.ResourcePools[0].Stemcell.URL).Should(ContainSubstring("esx"))
			})

			It("then it should have the correct job config to deploy a bosh", func() {
				Ω(len(manifest.Jobs)).Should(Equal(1))
			})

			It("then it should properly define job properties", func() {
				Ω(len(manifest.Jobs[0].Properties)).Should(Equal(9))
				Ω(func() (r []string) {
					for n := range manifest.Jobs[0].Properties {
						r = append(r, n)
					}
					return
				}()).Should(ConsistOf("nats", "postgres", "blobstore", "director", "hm", "vcenter", "agent", "ntp", "registry"))
			})

			It("then it should properly define job templates", func() {
				Ω(len(manifest.Jobs[0].Templates)).Should(Equal(7))
				Ω(func() (r []string) {
					for _, v := range manifest.Jobs[0].Templates {
						r = append(r, v.Name)
					}
					return
				}()).Should(ConsistOf("nats", "postgres", "blobstore", "director", "health_monitor", "vsphere_cpi", "registry"))
			})

			It("then it should properly define job networks", func() {
				Ω(len(manifest.Jobs[0].Networks)).Should(Equal(1))
				Ω(func() (r []string) {
					for _, v := range manifest.Jobs[0].Networks {
						r = append(r, v.Name)
					}
					return
				}()).Should(ConsistOf("private"))
			})

			It("then it should properly define vcenter properties", func() {
				Ω(manifest.Jobs[0].Properties).Should(HaveKey("vcenter"))
				vcenter := manifest.Jobs[0].Properties["vcenter"].(vsphere_cpi.Vcenter)
				Ω(vcenter.Address).Should(Equal("172.16.1.2"))
				Ω(vcenter.User).Should(Equal("vsadmin"))
				Ω(vcenter.Password).Should(Equal("<PASSWORD>"))
				Ω(vcenter.Datacenters).Should(HaveLen(1))
				dc := vcenter.Datacenters.(VSphereDatacenters)[0]
				Ω(dc.Name).Should(Equal("PCF_DC1"))
				Ω(dc.DatastorePattern).Should(Equal("DS1"))
				Ω(dc.PersistentDatastorePattern).Should(Equal("DS1_Persistent"))
				Ω(dc.DiskPath).Should(Equal("pcf_disks"))
				Ω(dc.TemplateFolder).Should(Equal("pcf_templates"))
				Ω(dc.VMFolder).Should(Equal("pcf_vms"))
				Ω(dc.Clusters).Should(HaveLen(1))
				Ω(dc.Clusters[0]).Should(Equal("PCF1"))
			})
		})
	})
})
{'fraction_non_alphanumeric': 0.1592708083473255, 'fraction_numerical': 0.03909810506116575, 'mean_word_length': 2.922859830667921, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 6, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2999740', 'n_tokens_mistral': 1795, 'n_tokens_neox': 1484, 'n_words': 210}