github.com/wanddynosios/cli/v8@v8.7.9-0.20240221182337-1a92e3a7017f/actor/v7pushaction/handle_buildpacks_override_test.go (about)

     1  package v7pushaction_test
     2  
     3  import (
     4  	"code.cloudfoundry.org/cli/command/translatableerror"
     5  	"code.cloudfoundry.org/cli/util/manifestparser"
     6  
     7  	. "code.cloudfoundry.org/cli/actor/v7pushaction"
     8  
     9  	. "github.com/onsi/ginkgo"
    10  	. "github.com/onsi/gomega"
    11  )
    12  
    13  var _ = Describe("HandleBuildpacksOverride", func() {
    14  	var (
    15  		originalManifest    manifestparser.Manifest
    16  		transformedManifest manifestparser.Manifest
    17  		overrides           FlagOverrides
    18  		executeErr          error
    19  	)
    20  
    21  	BeforeEach(func() {
    22  		originalManifest = manifestparser.Manifest{}
    23  		overrides = FlagOverrides{}
    24  	})
    25  
    26  	JustBeforeEach(func() {
    27  		transformedManifest, executeErr = HandleBuildpacksOverride(originalManifest, overrides)
    28  	})
    29  
    30  	When("buildpacks flag is set", func() {
    31  		When("there is a single app in the manifest with a buildpacks specified", func() {
    32  			BeforeEach(func() {
    33  				overrides.Buildpacks = []string{"buildpack-1", "buildpack-2"}
    34  
    35  				originalManifest.Applications = []manifestparser.Application{
    36  					{
    37  						RemainingManifestFields: map[string]interface{}{"buildpacks": []string{"buildpack-3"}},
    38  					},
    39  				}
    40  			})
    41  
    42  			It("will override the buildpacks in the manifest with the provided flag value", func() {
    43  				Expect(executeErr).To(Not(HaveOccurred()))
    44  				Expect(transformedManifest.Applications).To(ConsistOf(
    45  					manifestparser.Application{
    46  						RemainingManifestFields: map[string]interface{}{"buildpacks": []string{"buildpack-1", "buildpack-2"}},
    47  					},
    48  				))
    49  			})
    50  		})
    51  
    52  		When("there is a single app with --buildpack default override specified", func() {
    53  			BeforeEach(func() {
    54  				overrides.Buildpacks = []string{"default"}
    55  
    56  				originalManifest.Applications = []manifestparser.Application{
    57  					{
    58  						RemainingManifestFields: map[string]interface{}{"buildpacks": []string{"buildpack-3"}},
    59  					},
    60  				}
    61  			})
    62  
    63  			It("sets the buildpacks list in the manifest to be an empty array", func() {
    64  				Expect(executeErr).To(Not(HaveOccurred()))
    65  				Expect(transformedManifest.Applications).To(ConsistOf(
    66  					manifestparser.Application{
    67  						RemainingManifestFields: map[string]interface{}{"buildpacks": []string{}},
    68  					},
    69  				))
    70  			})
    71  		})
    72  
    73  		When("there is a single app with --buildpack null override specified", func() {
    74  			BeforeEach(func() {
    75  				overrides.Buildpacks = []string{"null"}
    76  
    77  				originalManifest.Applications = []manifestparser.Application{
    78  					{
    79  						RemainingManifestFields: map[string]interface{}{"buildpacks": []string{"buildpack-3"}},
    80  					},
    81  				}
    82  			})
    83  
    84  			It("sets the buildpacks list in the manifest to be an empty array", func() {
    85  				Expect(executeErr).To(Not(HaveOccurred()))
    86  				Expect(transformedManifest.Applications).To(ConsistOf(
    87  					manifestparser.Application{
    88  						RemainingManifestFields: map[string]interface{}{"buildpacks": []string{}},
    89  					},
    90  				))
    91  			})
    92  		})
    93  
    94  		When("there are multiple apps in the manifest", func() {
    95  			BeforeEach(func() {
    96  				overrides.Buildpacks = []string{"buildpack-1", "buildpack-2"}
    97  
    98  				originalManifest.Applications = []manifestparser.Application{
    99  					{},
   100  					{},
   101  				}
   102  			})
   103  
   104  			It("returns an error", func() {
   105  				Expect(executeErr).To(MatchError(translatableerror.CommandLineArgsWithMultipleAppsError{}))
   106  			})
   107  		})
   108  
   109  		When("when docker is set in the manifest", func() {
   110  			BeforeEach(func() {
   111  				overrides.Buildpacks = []string{"buildpack-1", "buildpack-2"}
   112  
   113  				originalManifest.Applications = []manifestparser.Application{
   114  					{
   115  						Name: "some-app",
   116  						Docker: &manifestparser.Docker{
   117  							Image: "nginx:latest",
   118  						},
   119  					},
   120  				}
   121  			})
   122  
   123  			It("returns an error", func() {
   124  				Expect(executeErr).To(MatchError(translatableerror.ArgumentManifestMismatchError{
   125  					Arg:              "--buildpack, -b",
   126  					ManifestProperty: "docker",
   127  				}))
   128  			})
   129  		})
   130  	})
   131  })