github.com/wanddynosios/cli/v8@v8.7.9-0.20240221182337-1a92e3a7017f/actor/v7pushaction/handle_docker_username_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("HandleDockerUsernameOverride", 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 = HandleDockerUsernameOverride(originalManifest, overrides)
    28  	})
    29  
    30  	When("docker username flag is set", func() {
    31  		When("there is a single app in the manifest without any docker info specified", func() {
    32  			BeforeEach(func() {
    33  				overrides.DockerUsername = "some-docker-username"
    34  
    35  				originalManifest.Applications = []manifestparser.Application{
    36  					{},
    37  				}
    38  			})
    39  
    40  			It("will populate the docker username in the manifest with the provided flag value", func() {
    41  				Expect(executeErr).To(Not(HaveOccurred()))
    42  				Expect(transformedManifest.Applications).To(ConsistOf(
    43  					manifestparser.Application{
    44  						Docker: &manifestparser.Docker{
    45  							Username: "some-docker-username",
    46  						},
    47  					},
    48  				))
    49  			})
    50  		})
    51  
    52  		When("there is a single app in the manifest with a docker username specified", func() {
    53  			BeforeEach(func() {
    54  				overrides.DockerUsername = "some-docker-username"
    55  
    56  				originalManifest.Applications = []manifestparser.Application{
    57  					{
    58  						Docker: &manifestparser.Docker{Username: "old-docker-username"},
    59  					},
    60  				}
    61  			})
    62  
    63  			It("will override the docker username in the manifest with the provided flag value", func() {
    64  				Expect(executeErr).To(Not(HaveOccurred()))
    65  				Expect(transformedManifest.Applications).To(ConsistOf(
    66  					manifestparser.Application{
    67  						Docker: &manifestparser.Docker{
    68  							Username: "some-docker-username",
    69  						},
    70  					},
    71  				))
    72  			})
    73  		})
    74  
    75  		When("there are multiple apps in the manifest", func() {
    76  			BeforeEach(func() {
    77  				overrides.DockerUsername = "some-docker-username"
    78  
    79  				originalManifest.Applications = []manifestparser.Application{
    80  					{},
    81  					{},
    82  				}
    83  			})
    84  
    85  			It("returns an error", func() {
    86  				Expect(executeErr).To(MatchError(translatableerror.CommandLineArgsWithMultipleAppsError{}))
    87  			})
    88  		})
    89  	})
    90  })