github.com/cloudfoundry/cli@v7.1.0+incompatible/actor/pushaction/command_line_settings_test.go (about)

     1  package pushaction_test
     2  
     3  import (
     4  	. "code.cloudfoundry.org/cli/actor/pushaction"
     5  	"code.cloudfoundry.org/cli/types"
     6  	"code.cloudfoundry.org/cli/util/manifest"
     7  	. "github.com/onsi/ginkgo"
     8  	. "github.com/onsi/ginkgo/extensions/table"
     9  	. "github.com/onsi/gomega"
    10  )
    11  
    12  var _ = Describe("CommandLineSettings", func() {
    13  	var (
    14  		settings CommandLineSettings
    15  	)
    16  
    17  	BeforeEach(func() {
    18  		settings = CommandLineSettings{}
    19  	})
    20  
    21  	DescribeTable("OverrideManifestSettings",
    22  		func(settings CommandLineSettings, input manifest.Application, output manifest.Application) {
    23  			Expect(settings.OverrideManifestSettings(input)).To(Equal(output))
    24  		},
    25  		Entry("single buildpack overrides single buildpack",
    26  			CommandLineSettings{Buildpacks: []string{"sixpack"}},
    27  			manifest.Application{Buildpack: types.FilteredString{IsSet: true, Value: "not-sixpack"}},
    28  			manifest.Application{Buildpack: types.FilteredString{IsSet: true, Value: "sixpack"}, Buildpacks: nil},
    29  		),
    30  		Entry("single buildpack overrides multiple buildpacks",
    31  			CommandLineSettings{Buildpacks: []string{"sixpack"}},
    32  			manifest.Application{Buildpacks: []string{"not-sixpack", "definitely-not-sixpack"}},
    33  			manifest.Application{Buildpack: types.FilteredString{IsSet: true, Value: "sixpack"}, Buildpacks: nil},
    34  		),
    35  		Entry("multiple buildpack overrides single buildpack",
    36  			CommandLineSettings{Buildpacks: []string{"sixpack", "sixpack2.0"}},
    37  			manifest.Application{Buildpack: types.FilteredString{IsSet: true, Value: "not-sixpack"}},
    38  			manifest.Application{
    39  				Buildpack:  types.FilteredString{},
    40  				Buildpacks: []string{"sixpack", "sixpack2.0"},
    41  			}),
    42  		Entry("multiple buildpack overrides multiple buildpacks",
    43  			CommandLineSettings{Buildpacks: []string{"sixpack", "sixpack2.0"}},
    44  			manifest.Application{Buildpacks: []string{"not-sixpack", "definitely-not-sixpack"}},
    45  			manifest.Application{
    46  				Buildpack:  types.FilteredString{},
    47  				Buildpacks: []string{"sixpack", "sixpack2.0"},
    48  			}),
    49  		Entry("passes through single buildpack",
    50  			CommandLineSettings{Buildpacks: nil},
    51  			manifest.Application{Buildpack: types.FilteredString{IsSet: true, Value: "not-sixpack"}},
    52  			manifest.Application{Buildpack: types.FilteredString{IsSet: true, Value: "not-sixpack"}},
    53  		),
    54  		Entry("passes through multiple buildpacks",
    55  			CommandLineSettings{Buildpacks: nil},
    56  			manifest.Application{Buildpacks: []string{"not-sixpack", "definitely-not-sixpack"}},
    57  			manifest.Application{Buildpacks: []string{"not-sixpack", "definitely-not-sixpack"}},
    58  		),
    59  		Entry("handles autodetect on single buildpack",
    60  			CommandLineSettings{Buildpacks: []string{"default"}},
    61  			manifest.Application{Buildpacks: []string{"not-sixpack", "definitely-not-sixpack"}},
    62  			manifest.Application{Buildpack: types.FilteredString{IsSet: true, Value: ""}},
    63  		),
    64  		Entry("overrides command",
    65  			CommandLineSettings{Command: types.FilteredString{IsSet: true, Value: "not-steve"}},
    66  			manifest.Application{Command: types.FilteredString{IsSet: true, Value: "steve"}},
    67  			manifest.Application{Command: types.FilteredString{IsSet: true, Value: "not-steve"}},
    68  		),
    69  		Entry("passes through command",
    70  			CommandLineSettings{},
    71  			manifest.Application{Command: types.FilteredString{IsSet: true, Value: "steve"}},
    72  			manifest.Application{Command: types.FilteredString{IsSet: true, Value: "steve"}},
    73  		),
    74  		Entry("overrides domain",
    75  			CommandLineSettings{DefaultRouteDomain: "not-steve"},
    76  			manifest.Application{Domain: "steve"},
    77  			manifest.Application{Domain: "not-steve"},
    78  		),
    79  		Entry("passes through domain",
    80  			CommandLineSettings{},
    81  			manifest.Application{Domain: "steve"},
    82  			manifest.Application{Domain: "steve"},
    83  		),
    84  		Entry("overrides hostname",
    85  			CommandLineSettings{DefaultRouteHostname: "not-steve"},
    86  			manifest.Application{Hostname: "steve"},
    87  			manifest.Application{Hostname: "not-steve"},
    88  		),
    89  		Entry("passes through hostname",
    90  			CommandLineSettings{},
    91  			manifest.Application{Hostname: "steve"},
    92  			manifest.Application{Hostname: "steve"},
    93  		),
    94  		Entry("overrides disk quota",
    95  			CommandLineSettings{DiskQuota: 1024},
    96  			manifest.Application{DiskQuota: types.NullByteSizeInMb{Value: 512, IsSet: true}},
    97  			manifest.Application{DiskQuota: types.NullByteSizeInMb{Value: 1024, IsSet: true}},
    98  		),
    99  		Entry("passes through disk quota",
   100  			CommandLineSettings{},
   101  			manifest.Application{DiskQuota: types.NullByteSizeInMb{Value: 1024, IsSet: true}},
   102  			manifest.Application{DiskQuota: types.NullByteSizeInMb{Value: 1024, IsSet: true}},
   103  		),
   104  		Entry("overrides docker image",
   105  			CommandLineSettings{DockerImage: "not-steve"},
   106  			manifest.Application{DockerImage: "steve"},
   107  			manifest.Application{DockerImage: "not-steve"},
   108  		),
   109  		Entry("passes through docker image",
   110  			CommandLineSettings{},
   111  			manifest.Application{DockerImage: "steve"},
   112  			manifest.Application{DockerImage: "steve"},
   113  		),
   114  		Entry("overrides docker username",
   115  			CommandLineSettings{DockerUsername: "not-steve"},
   116  			manifest.Application{DockerUsername: "steve"},
   117  			manifest.Application{DockerUsername: "not-steve"},
   118  		),
   119  		Entry("passes through docker username",
   120  			CommandLineSettings{},
   121  			manifest.Application{DockerUsername: "steve"},
   122  			manifest.Application{DockerUsername: "steve"},
   123  		),
   124  		Entry("overrides docker password",
   125  			CommandLineSettings{DockerPassword: "not-steve"},
   126  			manifest.Application{DockerPassword: "steve"},
   127  			manifest.Application{DockerPassword: "not-steve"},
   128  		),
   129  		Entry("passes through docker password",
   130  			CommandLineSettings{},
   131  			manifest.Application{DockerPassword: "steve"},
   132  			manifest.Application{DockerPassword: "steve"},
   133  		),
   134  		Entry("overrides droplet path",
   135  			CommandLineSettings{DropletPath: "some-path", CurrentDirectory: "some-dir"},
   136  			manifest.Application{DropletPath: "no-path"},
   137  			manifest.Application{DropletPath: "some-path", Path: ""},
   138  		),
   139  		Entry("overrides health check timeout",
   140  			CommandLineSettings{HealthCheckTimeout: 1024},
   141  			manifest.Application{HealthCheckTimeout: 512},
   142  			manifest.Application{HealthCheckTimeout: 1024},
   143  		),
   144  		Entry("passes through health check timeout",
   145  			CommandLineSettings{},
   146  			manifest.Application{HealthCheckTimeout: 1024},
   147  			manifest.Application{HealthCheckTimeout: 1024},
   148  		),
   149  		Entry("overrides health check type",
   150  			CommandLineSettings{HealthCheckType: "port"},
   151  			manifest.Application{HealthCheckType: "http"},
   152  			manifest.Application{HealthCheckType: "port"},
   153  		),
   154  		Entry("passes through health check type",
   155  			CommandLineSettings{},
   156  			manifest.Application{HealthCheckType: "http"},
   157  			manifest.Application{HealthCheckType: "http"},
   158  		),
   159  		Entry("overrides instances",
   160  			CommandLineSettings{Instances: types.NullInt{Value: 1024, IsSet: true}},
   161  			manifest.Application{Instances: types.NullInt{Value: 512, IsSet: true}},
   162  			manifest.Application{Instances: types.NullInt{Value: 1024, IsSet: true}},
   163  		),
   164  		Entry("passes through instances",
   165  			CommandLineSettings{},
   166  			manifest.Application{Instances: types.NullInt{Value: 1024, IsSet: true}},
   167  			manifest.Application{Instances: types.NullInt{Value: 1024, IsSet: true}},
   168  		),
   169  		Entry("overrides memory",
   170  			CommandLineSettings{Memory: 1024},
   171  			manifest.Application{Memory: types.NullByteSizeInMb{Value: 512, IsSet: true}},
   172  			manifest.Application{Memory: types.NullByteSizeInMb{Value: 1024, IsSet: true}},
   173  		),
   174  		Entry("passes through memory",
   175  			CommandLineSettings{},
   176  			manifest.Application{Memory: types.NullByteSizeInMb{Value: 1024, IsSet: true}},
   177  			manifest.Application{Memory: types.NullByteSizeInMb{Value: 1024, IsSet: true}},
   178  		),
   179  		Entry("overrides name",
   180  			CommandLineSettings{Name: "not-steve"},
   181  			manifest.Application{Name: "steve"},
   182  			manifest.Application{Name: "not-steve"},
   183  		),
   184  		Entry("passes through name",
   185  			CommandLineSettings{},
   186  			manifest.Application{Name: "steve"},
   187  			manifest.Application{Name: "steve"},
   188  		),
   189  		Entry("overrides stack name",
   190  			CommandLineSettings{StackName: "not-steve"},
   191  			manifest.Application{StackName: "steve"},
   192  			manifest.Application{StackName: "not-steve"},
   193  		),
   194  		Entry("overrides no hostname",
   195  			CommandLineSettings{NoHostname: true},
   196  			manifest.Application{},
   197  			manifest.Application{NoHostname: true},
   198  		),
   199  		Entry("passes through no hostname",
   200  			CommandLineSettings{},
   201  			manifest.Application{NoHostname: true},
   202  			manifest.Application{NoHostname: true},
   203  		),
   204  		Entry("no path, docker image, or droplet",
   205  			CommandLineSettings{CurrentDirectory: "some-dir"},
   206  			manifest.Application{},
   207  			manifest.Application{Path: "some-dir"},
   208  		),
   209  		Entry("overrides no route",
   210  			CommandLineSettings{NoRoute: true},
   211  			manifest.Application{},
   212  			manifest.Application{NoRoute: true},
   213  		),
   214  		Entry("passes through no route",
   215  			CommandLineSettings{},
   216  			manifest.Application{NoRoute: true},
   217  			manifest.Application{NoRoute: true},
   218  		),
   219  		Entry("overrides random route",
   220  			CommandLineSettings{RandomRoute: true},
   221  			manifest.Application{},
   222  			manifest.Application{RandomRoute: true},
   223  		),
   224  		Entry("passes through random route",
   225  			CommandLineSettings{},
   226  			manifest.Application{RandomRoute: true},
   227  			manifest.Application{RandomRoute: true},
   228  		),
   229  		Entry("hostname overrides random route",
   230  			CommandLineSettings{DefaultRouteHostname: "scott's merchandise"},
   231  			manifest.Application{RandomRoute: true},
   232  			manifest.Application{Hostname: "scott's merchandise", RandomRoute: false},
   233  		),
   234  		Entry("overrides route path",
   235  			CommandLineSettings{RoutePath: "/some-route-path"},
   236  			manifest.Application{},
   237  			manifest.Application{RoutePath: "/some-route-path"},
   238  		),
   239  		Entry("passes through route path",
   240  			CommandLineSettings{},
   241  			manifest.Application{RoutePath: "/some-route-path"},
   242  			manifest.Application{RoutePath: "/some-route-path"},
   243  		),
   244  		Entry("passes through stack name",
   245  			CommandLineSettings{},
   246  			manifest.Application{StackName: "steve"},
   247  			manifest.Application{StackName: "steve"},
   248  		),
   249  	)
   250  
   251  	Describe("OverrideManifestSettings", func() {
   252  		// more tests under command_line_settings_*OS*_test.go
   253  
   254  		var input, output manifest.Application
   255  
   256  		BeforeEach(func() {
   257  			input.Name = "steve"
   258  		})
   259  
   260  		JustBeforeEach(func() {
   261  			output = settings.OverrideManifestSettings(input)
   262  		})
   263  
   264  		Describe("name", func() {
   265  			When("the command line settings provides a name", func() {
   266  				BeforeEach(func() {
   267  					settings.Name = "not-steve"
   268  				})
   269  
   270  				It("overrides the name", func() {
   271  					Expect(output.Name).To(Equal("not-steve"))
   272  				})
   273  			})
   274  
   275  			When("the command line settings name is blank", func() {
   276  				It("passes the manifest name through", func() {
   277  					Expect(output.Name).To(Equal("steve"))
   278  				})
   279  			})
   280  		})
   281  	})
   282  })