github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+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("overrides buildpack name",
    27  			CommandLineSettings{Buildpack: types.FilteredString{IsSet: true, Value: "sixpack"}},
    28  			manifest.Application{Buildpack: types.FilteredString{IsSet: true, Value: "not-sixpack"}},
    29  			manifest.Application{Buildpack: types.FilteredString{IsSet: true, Value: "sixpack"}},
    30  		),
    31  		Entry("passes through buildpack name",
    32  			CommandLineSettings{Buildpack: types.FilteredString{IsSet: false, Value: ""}},
    33  			manifest.Application{Buildpack: types.FilteredString{IsSet: true, Value: "not-sixpack"}},
    34  			manifest.Application{Buildpack: types.FilteredString{IsSet: true, Value: "not-sixpack"}},
    35  		),
    36  		Entry("overrides command",
    37  			CommandLineSettings{Command: types.FilteredString{IsSet: true, Value: "not-steve"}},
    38  			manifest.Application{Command: types.FilteredString{IsSet: true, Value: "steve"}},
    39  			manifest.Application{Command: types.FilteredString{IsSet: true, Value: "not-steve"}},
    40  		),
    41  		Entry("passes through command",
    42  			CommandLineSettings{},
    43  			manifest.Application{Command: types.FilteredString{IsSet: true, Value: "steve"}},
    44  			manifest.Application{Command: types.FilteredString{IsSet: true, Value: "steve"}},
    45  		),
    46  		Entry("overrides domain",
    47  			CommandLineSettings{DefaultRouteDomain: "not-steve"},
    48  			manifest.Application{Domain: "steve"},
    49  			manifest.Application{Domain: "not-steve"},
    50  		),
    51  		Entry("passes through domain",
    52  			CommandLineSettings{},
    53  			manifest.Application{Domain: "steve"},
    54  			manifest.Application{Domain: "steve"},
    55  		),
    56  		Entry("overrides hostname",
    57  			CommandLineSettings{DefaultRouteHostname: "not-steve"},
    58  			manifest.Application{Hostname: "steve"},
    59  			manifest.Application{Hostname: "not-steve"},
    60  		),
    61  		Entry("passes through hostname",
    62  			CommandLineSettings{},
    63  			manifest.Application{Hostname: "steve"},
    64  			manifest.Application{Hostname: "steve"},
    65  		),
    66  		Entry("overrides disk quota",
    67  			CommandLineSettings{DiskQuota: 1024},
    68  			manifest.Application{DiskQuota: types.NullByteSizeInMb{Value: 512, IsSet: true}},
    69  			manifest.Application{DiskQuota: types.NullByteSizeInMb{Value: 1024, IsSet: true}},
    70  		),
    71  		Entry("passes through disk quota",
    72  			CommandLineSettings{},
    73  			manifest.Application{DiskQuota: types.NullByteSizeInMb{Value: 1024, IsSet: true}},
    74  			manifest.Application{DiskQuota: types.NullByteSizeInMb{Value: 1024, IsSet: true}},
    75  		),
    76  		Entry("overrides docker image",
    77  			CommandLineSettings{DockerImage: "not-steve"},
    78  			manifest.Application{DockerImage: "steve"},
    79  			manifest.Application{DockerImage: "not-steve"},
    80  		),
    81  		Entry("passes through docker image",
    82  			CommandLineSettings{},
    83  			manifest.Application{DockerImage: "steve"},
    84  			manifest.Application{DockerImage: "steve"},
    85  		),
    86  		Entry("overrides docker username",
    87  			CommandLineSettings{DockerUsername: "not-steve"},
    88  			manifest.Application{DockerUsername: "steve"},
    89  			manifest.Application{DockerUsername: "not-steve"},
    90  		),
    91  		Entry("passes through docker username",
    92  			CommandLineSettings{},
    93  			manifest.Application{DockerUsername: "steve"},
    94  			manifest.Application{DockerUsername: "steve"},
    95  		),
    96  		Entry("overrides docker password",
    97  			CommandLineSettings{DockerPassword: "not-steve"},
    98  			manifest.Application{DockerPassword: "steve"},
    99  			manifest.Application{DockerPassword: "not-steve"},
   100  		),
   101  		Entry("passes through docker password",
   102  			CommandLineSettings{},
   103  			manifest.Application{DockerPassword: "steve"},
   104  			manifest.Application{DockerPassword: "steve"},
   105  		),
   106  		Entry("overrides health check timeout",
   107  			CommandLineSettings{HealthCheckTimeout: 1024},
   108  			manifest.Application{HealthCheckTimeout: 512},
   109  			manifest.Application{HealthCheckTimeout: 1024},
   110  		),
   111  		Entry("passes through health check timeout",
   112  			CommandLineSettings{},
   113  			manifest.Application{HealthCheckTimeout: 1024},
   114  			manifest.Application{HealthCheckTimeout: 1024},
   115  		),
   116  		Entry("overrides health check type",
   117  			CommandLineSettings{HealthCheckType: "port"},
   118  			manifest.Application{HealthCheckType: "http"},
   119  			manifest.Application{HealthCheckType: "port"},
   120  		),
   121  		Entry("passes through health check type",
   122  			CommandLineSettings{},
   123  			manifest.Application{HealthCheckType: "http"},
   124  			manifest.Application{HealthCheckType: "http"},
   125  		),
   126  		Entry("overrides instances",
   127  			CommandLineSettings{Instances: types.NullInt{Value: 1024, IsSet: true}},
   128  			manifest.Application{Instances: types.NullInt{Value: 512, IsSet: true}},
   129  			manifest.Application{Instances: types.NullInt{Value: 1024, IsSet: true}},
   130  		),
   131  		Entry("passes through instances",
   132  			CommandLineSettings{},
   133  			manifest.Application{Instances: types.NullInt{Value: 1024, IsSet: true}},
   134  			manifest.Application{Instances: types.NullInt{Value: 1024, IsSet: true}},
   135  		),
   136  		Entry("overrides memory",
   137  			CommandLineSettings{Memory: 1024},
   138  			manifest.Application{Memory: types.NullByteSizeInMb{Value: 512, IsSet: true}},
   139  			manifest.Application{Memory: types.NullByteSizeInMb{Value: 1024, IsSet: true}},
   140  		),
   141  		Entry("passes through memory",
   142  			CommandLineSettings{},
   143  			manifest.Application{Memory: types.NullByteSizeInMb{Value: 1024, IsSet: true}},
   144  			manifest.Application{Memory: types.NullByteSizeInMb{Value: 1024, IsSet: true}},
   145  		),
   146  		Entry("overrides name",
   147  			CommandLineSettings{Name: "not-steve"},
   148  			manifest.Application{Name: "steve"},
   149  			manifest.Application{Name: "not-steve"},
   150  		),
   151  		Entry("passes through name",
   152  			CommandLineSettings{},
   153  			manifest.Application{Name: "steve"},
   154  			manifest.Application{Name: "steve"},
   155  		),
   156  		Entry("overrides stack name",
   157  			CommandLineSettings{StackName: "not-steve"},
   158  			manifest.Application{StackName: "steve"},
   159  			manifest.Application{StackName: "not-steve"},
   160  		),
   161  		Entry("overrides no hostname",
   162  			CommandLineSettings{NoHostname: true},
   163  			manifest.Application{},
   164  			manifest.Application{NoHostname: true},
   165  		),
   166  		Entry("passes through no hostname",
   167  			CommandLineSettings{},
   168  			manifest.Application{NoHostname: true},
   169  			manifest.Application{NoHostname: true},
   170  		),
   171  		Entry("overrides no route",
   172  			CommandLineSettings{NoRoute: true},
   173  			manifest.Application{},
   174  			manifest.Application{NoRoute: true},
   175  		),
   176  		Entry("passes through no route",
   177  			CommandLineSettings{},
   178  			manifest.Application{NoRoute: true},
   179  			manifest.Application{NoRoute: true},
   180  		),
   181  		Entry("overrides random route",
   182  			CommandLineSettings{RandomRoute: true},
   183  			manifest.Application{},
   184  			manifest.Application{RandomRoute: true},
   185  		),
   186  		Entry("passes through random route",
   187  			CommandLineSettings{},
   188  			manifest.Application{RandomRoute: true},
   189  			manifest.Application{RandomRoute: true},
   190  		),
   191  		Entry("overrides route path",
   192  			CommandLineSettings{RoutePath: "/some-route-path"},
   193  			manifest.Application{},
   194  			manifest.Application{RoutePath: "/some-route-path"},
   195  		),
   196  		Entry("passes through route path",
   197  			CommandLineSettings{},
   198  			manifest.Application{RoutePath: "/some-route-path"},
   199  			manifest.Application{RoutePath: "/some-route-path"},
   200  		),
   201  		Entry("passes through stack name",
   202  			CommandLineSettings{},
   203  			manifest.Application{StackName: "steve"},
   204  			manifest.Application{StackName: "steve"},
   205  		),
   206  	)
   207  
   208  	Describe("OverrideManifestSettings", func() {
   209  		// more tests under command_line_settings_*OS*_test.go
   210  
   211  		var input, output manifest.Application
   212  
   213  		BeforeEach(func() {
   214  			input.Name = "steve"
   215  		})
   216  
   217  		JustBeforeEach(func() {
   218  			output = settings.OverrideManifestSettings(input)
   219  		})
   220  
   221  		Describe("name", func() {
   222  			Context("when the command line settings provides a name", func() {
   223  				BeforeEach(func() {
   224  					settings.Name = "not-steve"
   225  				})
   226  
   227  				It("overrides the name", func() {
   228  					Expect(output.Name).To(Equal("not-steve"))
   229  				})
   230  			})
   231  
   232  			Context("when the command line settings name is blank", func() {
   233  				It("passes the manifest name through", func() {
   234  					Expect(output.Name).To(Equal("steve"))
   235  				})
   236  			})
   237  		})
   238  	})
   239  })