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