github.com/wanddynosios/cli/v8@v8.7.9-0.20240221182337-1a92e3a7017f/util/manifestparser/process_test.go (about)

     1  package manifestparser_test
     2  
     3  import (
     4  	. "code.cloudfoundry.org/cli/util/manifestparser"
     5  	. "github.com/onsi/ginkgo"
     6  	. "github.com/onsi/gomega"
     7  	"gopkg.in/yaml.v2"
     8  )
     9  
    10  var _ = Describe("Process", func() {
    11  	Describe("SetStartCommand", func() {
    12  		var (
    13  			process Process
    14  			command string
    15  		)
    16  
    17  		BeforeEach(func() {
    18  			process = Process{}
    19  			command = "./start.sh"
    20  		})
    21  
    22  		JustBeforeEach(func() {
    23  			process.SetStartCommand(command)
    24  		})
    25  
    26  		When("the remaining fields map exists", func() {
    27  			BeforeEach(func() {
    28  				process.RemainingManifestFields = map[string]interface{}{}
    29  			})
    30  
    31  			It("sets the start command in the map", func() {
    32  				Expect(process.RemainingManifestFields["command"]).To(Equal("./start.sh"))
    33  			})
    34  
    35  			When("the command is nil", func() {
    36  				BeforeEach(func() {
    37  					command = ""
    38  				})
    39  
    40  				It("sets the start command to nil in the map", func() {
    41  					Expect(process.RemainingManifestFields["command"]).To(BeNil())
    42  				})
    43  			})
    44  		})
    45  
    46  		When("the remaining fields map does not exist", func() {
    47  			It("sets the start command in the map", func() {
    48  				Expect(process.RemainingManifestFields["command"]).To(Equal("./start.sh"))
    49  			})
    50  		})
    51  	})
    52  	Describe("UnmarshalYAML", func() {
    53  		var (
    54  			yamlBytes []byte
    55  			process   Process
    56  			err       error
    57  		)
    58  		JustBeforeEach(func() {
    59  			process = Process{}
    60  			err = yaml.Unmarshal(yamlBytes, &process)
    61  		})
    62  		When("'disk_quota' (underscore, backwards-compatible) is specified", func() {
    63  			BeforeEach(func() {
    64  				yamlBytes = []byte("disk_quota: 5G")
    65  			})
    66  			It("unmarshals it properly", func() {
    67  				Expect(err).ToNot(HaveOccurred())
    68  				Expect(process).To(Equal(Process{DiskQuota: "5G", RemainingManifestFields: map[string]interface{}{}}))
    69  			})
    70  		})
    71  		When("'disk-quota' (hyphen, new convention) is specified", func() {
    72  			BeforeEach(func() {
    73  				yamlBytes = []byte("disk-quota: 5G")
    74  			})
    75  			It("unmarshals it properly", func() {
    76  				Expect(err).ToNot(HaveOccurred())
    77  				Expect(process).To(Equal(Process{DiskQuota: "5G", RemainingManifestFields: map[string]interface{}{}}))
    78  			})
    79  		})
    80  	})
    81  })