github.com/asifdxtreme/cli@v6.1.3-0.20150123051144-9ead8700b4ae+incompatible/cf/manifest/manifest_disk_repository_test.go (about)

     1  package manifest_test
     2  
     3  import (
     4  	"path/filepath"
     5  
     6  	. "github.com/cloudfoundry/cli/cf/manifest"
     7  	. "github.com/onsi/ginkgo"
     8  	. "github.com/onsi/gomega"
     9  )
    10  
    11  var _ = Describe("ManifestDiskRepository", func() {
    12  	var repo ManifestRepository
    13  
    14  	BeforeEach(func() {
    15  		repo = NewManifestDiskRepository()
    16  	})
    17  
    18  	Describe("given a directory containing a file called 'manifest.yml'", func() {
    19  		It("reads that file", func() {
    20  			m, err := repo.ReadManifest("../../fixtures/manifests")
    21  
    22  			Expect(err).NotTo(HaveOccurred())
    23  			Expect(m.Path).To(Equal(filepath.Clean("../../fixtures/manifests/manifest.yml")))
    24  
    25  			applications, err := m.Applications()
    26  			Expect(err).NotTo(HaveOccurred())
    27  			Expect(*applications[0].Name).To(Equal("from-default-manifest"))
    28  		})
    29  	})
    30  
    31  	Describe("given a directory that doesn't contain a file called 'manifest.y{a}ml'", func() {
    32  		It("returns an error", func() {
    33  			m, err := repo.ReadManifest("../../fixtures")
    34  
    35  			Expect(err).To(HaveOccurred())
    36  			Expect(m.Path).To(BeEmpty())
    37  		})
    38  	})
    39  
    40  	Describe("given a directory that contains a file called 'manifest.yaml'", func() {
    41  		It("reads that file", func() {
    42  			m, err := repo.ReadManifest("../../fixtures/manifests/only_yaml")
    43  
    44  			Expect(err).NotTo(HaveOccurred())
    45  			Expect(m.Path).To(Equal(filepath.Clean("../../fixtures/manifests/only_yaml/manifest.yaml")))
    46  
    47  			applications, err := m.Applications()
    48  			Expect(err).NotTo(HaveOccurred())
    49  			Expect(*applications[0].Name).To(Equal("from-default-manifest"))
    50  		})
    51  	})
    52  
    53  	Describe("given a directory contains files called 'manifest.yml' and 'manifest.yaml'", func() {
    54  		It("reads the file named 'manifest.yml'", func() {
    55  			m, err := repo.ReadManifest("../../fixtures/manifests/both_yaml_yml")
    56  
    57  			Expect(err).NotTo(HaveOccurred())
    58  			Expect(m.Path).To(Equal(filepath.Clean("../../fixtures/manifests/both_yaml_yml/manifest.yml")))
    59  
    60  			applications, err := m.Applications()
    61  			Expect(err).NotTo(HaveOccurred())
    62  			Expect(*applications[0].Name).To(Equal("yml-extension"))
    63  		})
    64  	})
    65  
    66  	Describe("given a path to a file", func() {
    67  		var (
    68  			inputPath string
    69  			m         *Manifest
    70  			err       error
    71  		)
    72  
    73  		BeforeEach(func() {
    74  			inputPath = filepath.Clean("../../fixtures/manifests/different-manifest.yml")
    75  			m, err = repo.ReadManifest(inputPath)
    76  		})
    77  
    78  		It("reads the file at that path", func() {
    79  			Expect(err).NotTo(HaveOccurred())
    80  			Expect(m.Path).To(Equal(inputPath))
    81  
    82  			applications, err := m.Applications()
    83  			Expect(err).NotTo(HaveOccurred())
    84  			Expect(*applications[0].Name).To(Equal("from-different-manifest"))
    85  		})
    86  
    87  		It("passes the base directory to the manifest file", func() {
    88  			applications, err := m.Applications()
    89  			Expect(err).NotTo(HaveOccurred())
    90  			Expect(len(applications)).To(Equal(1))
    91  			Expect(*applications[0].Name).To(Equal("from-different-manifest"))
    92  
    93  			appPath := filepath.Clean("../../fixtures/manifests")
    94  			Expect(*applications[0].Path).To(Equal(appPath))
    95  		})
    96  	})
    97  
    98  	Describe("given a path to a file that doesn't exist", func() {
    99  		It("returns an error", func() {
   100  			_, err := repo.ReadManifest("some/path/that/doesnt/exist/manifest.yml")
   101  			Expect(err).To(HaveOccurred())
   102  		})
   103  
   104  		It("returns empty string for the manifest path", func() {
   105  			m, _ := repo.ReadManifest("some/path/that/doesnt/exist/manifest.yml")
   106  			Expect(m.Path).To(Equal(""))
   107  		})
   108  	})
   109  
   110  	Describe("when the manifest is not valid", func() {
   111  		It("returns an error", func() {
   112  			_, err := repo.ReadManifest("../../fixtures/manifests/empty-manifest.yml")
   113  			Expect(err).To(HaveOccurred())
   114  		})
   115  
   116  		It("returns the path to the manifest", func() {
   117  			inputPath := filepath.Clean("../../fixtures/manifests/empty-manifest.yml")
   118  			m, _ := repo.ReadManifest(inputPath)
   119  			Expect(m.Path).To(Equal(inputPath))
   120  		})
   121  	})
   122  
   123  	It("converts nested maps to generic maps", func() {
   124  		m, err := repo.ReadManifest("../../fixtures/manifests/different-manifest.yml")
   125  		Expect(err).NotTo(HaveOccurred())
   126  
   127  		applications, err := m.Applications()
   128  		Expect(err).NotTo(HaveOccurred())
   129  		Expect(*applications[0].EnvironmentVars).To(Equal(map[string]interface{}{
   130  			"LD_LIBRARY_PATH": "/usr/lib/somewhere",
   131  		}))
   132  	})
   133  
   134  	It("merges manifests with their 'inherited' manifests", func() {
   135  		m, err := repo.ReadManifest("../../fixtures/manifests/inherited-manifest.yml")
   136  		Expect(err).NotTo(HaveOccurred())
   137  
   138  		applications, err := m.Applications()
   139  		Expect(err).NotTo(HaveOccurred())
   140  		Expect(*applications[0].Name).To(Equal("base-app"))
   141  		Expect(*applications[0].ServicesToBind).To(Equal([]string{"base-service"}))
   142  		Expect(*applications[0].EnvironmentVars).To(Equal(map[string]interface{}{
   143  			"foo":                "bar",
   144  			"will-be-overridden": "my-value",
   145  		}))
   146  
   147  		Expect(*applications[1].Name).To(Equal("my-app"))
   148  
   149  		env := *applications[1].EnvironmentVars
   150  		Expect(env["will-be-overridden"]).To(Equal("my-value"))
   151  		Expect(env["foo"]).To(Equal("bar"))
   152  
   153  		services := *applications[1].ServicesToBind
   154  		Expect(services).To(Equal([]string{"base-service", "foo-service"}))
   155  	})
   156  })