github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+incompatible/actor/v7pushaction/handle_health_check_type_override_test.go (about)

     1  package v7pushaction_test
     2  
     3  import (
     4  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/constant"
     5  	"code.cloudfoundry.org/cli/command/translatableerror"
     6  	"code.cloudfoundry.org/cli/util/manifestparser"
     7  
     8  	. "code.cloudfoundry.org/cli/actor/v7pushaction"
     9  
    10  	. "github.com/onsi/ginkgo"
    11  	. "github.com/onsi/gomega"
    12  )
    13  
    14  var _ = Describe("HandleHealthCheckTypeOverride", func() {
    15  	var (
    16  		originalManifest    manifestparser.Manifest
    17  		transformedManifest manifestparser.Manifest
    18  		overrides           FlagOverrides
    19  		executeErr          error
    20  	)
    21  
    22  	BeforeEach(func() {
    23  		originalManifest = manifestparser.Manifest{}
    24  		overrides = FlagOverrides{}
    25  	})
    26  
    27  	JustBeforeEach(func() {
    28  		transformedManifest, executeErr = HandleHealthCheckTypeOverride(originalManifest, overrides)
    29  	})
    30  
    31  	When("manifest web process does not specify health check type", func() {
    32  		BeforeEach(func() {
    33  			originalManifest.Applications = []manifestparser.Application{
    34  				{
    35  					Processes: []manifestparser.Process{
    36  						{Type: "web"},
    37  					},
    38  				},
    39  			}
    40  		})
    41  
    42  		When("health check type is not set on the flag overrides", func() {
    43  			It("does not change the manifest", func() {
    44  				Expect(executeErr).ToNot(HaveOccurred())
    45  				Expect(transformedManifest).To(Equal(originalManifest))
    46  			})
    47  		})
    48  
    49  		When("health check type set on the flag overrides", func() {
    50  			BeforeEach(func() {
    51  				overrides.HealthCheckType = constant.HTTP
    52  			})
    53  
    54  			It("changes the health check type of the web process in the manifest", func() {
    55  				Expect(executeErr).ToNot(HaveOccurred())
    56  				Expect(transformedManifest.Applications).To(ConsistOf(
    57  					manifestparser.Application{
    58  						Processes: []manifestparser.Process{
    59  							{Type: "web", HealthCheckType: constant.HTTP},
    60  						},
    61  					},
    62  				))
    63  			})
    64  		})
    65  	})
    66  
    67  	When("health check type flag is set, and manifest app has non-web processes", func() {
    68  		BeforeEach(func() {
    69  			overrides.HealthCheckType = constant.HTTP
    70  
    71  			originalManifest.Applications = []manifestparser.Application{
    72  				{
    73  					Processes: []manifestparser.Process{
    74  						{Type: "worker", HealthCheckType: constant.Port},
    75  					},
    76  				},
    77  			}
    78  		})
    79  
    80  		It("changes the health check type in the app level only", func() {
    81  			Expect(executeErr).ToNot(HaveOccurred())
    82  			Expect(transformedManifest.Applications).To(ConsistOf(
    83  				manifestparser.Application{
    84  					HealthCheckType: constant.HTTP,
    85  					Processes: []manifestparser.Process{
    86  						{Type: "worker", HealthCheckType: constant.Port},
    87  					},
    88  				},
    89  			))
    90  		})
    91  	})
    92  
    93  	When("health check type flag is set, and manifest app has web and non-web processes", func() {
    94  		BeforeEach(func() {
    95  			overrides.HealthCheckType = constant.HTTP
    96  
    97  			originalManifest.Applications = []manifestparser.Application{
    98  				{
    99  					Processes: []manifestparser.Process{
   100  						{Type: "worker", HealthCheckType: constant.Port},
   101  						{Type: "web", HealthCheckType: constant.Process},
   102  					},
   103  					HealthCheckType: constant.Port,
   104  				},
   105  			}
   106  		})
   107  
   108  		It("changes the health check type of the web process in the manifest", func() {
   109  			Expect(executeErr).ToNot(HaveOccurred())
   110  			Expect(transformedManifest.Applications).To(ConsistOf(
   111  				manifestparser.Application{
   112  					Processes: []manifestparser.Process{
   113  						{Type: "worker", HealthCheckType: constant.Port},
   114  						{Type: "web", HealthCheckType: constant.HTTP},
   115  					},
   116  					HealthCheckType: constant.Port,
   117  				},
   118  			))
   119  		})
   120  	})
   121  
   122  	When("health check type flag is set and there are multiple apps in the manifest", func() {
   123  		BeforeEach(func() {
   124  			overrides.HealthCheckType = constant.HTTP
   125  
   126  			originalManifest.Applications = []manifestparser.Application{
   127  				{},
   128  				{},
   129  			}
   130  		})
   131  
   132  		It("returns an error", func() {
   133  			Expect(executeErr).To(MatchError(translatableerror.CommandLineArgsWithMultipleAppsError{}))
   134  		})
   135  	})
   136  
   137  	When("health check type flag is not http but manifest contains endpoint", func() {
   138  		BeforeEach(func() {
   139  			overrides.HealthCheckType = constant.Port
   140  
   141  			originalManifest.Applications = []manifestparser.Application{
   142  				{
   143  					HealthCheckType:     constant.HTTP,
   144  					HealthCheckEndpoint: "/",
   145  				},
   146  			}
   147  		})
   148  
   149  		It("removes endpoint from the manifest and updated type", func() {
   150  
   151  			Expect(executeErr).ToNot(HaveOccurred())
   152  			Expect(transformedManifest.Applications).To(ConsistOf(
   153  				manifestparser.Application{
   154  					HealthCheckType: constant.Port,
   155  				},
   156  			))
   157  		})
   158  	})
   159  })