github.com/orange-cloudfoundry/cli@v7.1.0+incompatible/actor/v7action/process_health_check_test.go (about)

     1  package v7action_test
     2  
     3  import (
     4  	"errors"
     5  
     6  	"code.cloudfoundry.org/cli/actor/actionerror"
     7  	. "code.cloudfoundry.org/cli/actor/v7action"
     8  	"code.cloudfoundry.org/cli/actor/v7action/v7actionfakes"
     9  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3"
    10  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3/constant"
    11  	"code.cloudfoundry.org/cli/resources"
    12  	. "github.com/onsi/ginkgo"
    13  	. "github.com/onsi/gomega"
    14  )
    15  
    16  var _ = Describe("Process Health Check Actions", func() {
    17  	var (
    18  		actor                     *Actor
    19  		fakeCloudControllerClient *v7actionfakes.FakeCloudControllerClient
    20  	)
    21  
    22  	BeforeEach(func() {
    23  		fakeCloudControllerClient = new(v7actionfakes.FakeCloudControllerClient)
    24  		actor = NewActor(fakeCloudControllerClient, nil, nil, nil, nil, nil)
    25  	})
    26  
    27  	Describe("ProcessHealthChecks", func() {
    28  		var healthchecks ProcessHealthChecks
    29  
    30  		BeforeEach(func() {
    31  			healthchecks = ProcessHealthChecks{
    32  				{
    33  					ProcessType:     "worker",
    34  					HealthCheckType: constant.Process,
    35  				},
    36  				{
    37  					ProcessType:     "console",
    38  					HealthCheckType: constant.Process,
    39  				},
    40  				{
    41  					ProcessType:     constant.ProcessTypeWeb,
    42  					HealthCheckType: constant.HTTP,
    43  					Endpoint:        constant.ProcessHealthCheckEndpointDefault,
    44  				},
    45  			}
    46  		})
    47  
    48  		Describe("Sort", func() {
    49  			It("sorts healthchecks with web first and then alphabetically sorted", func() {
    50  				healthchecks.Sort()
    51  				Expect(healthchecks[0].ProcessType).To(Equal(constant.ProcessTypeWeb))
    52  				Expect(healthchecks[1].ProcessType).To(Equal("console"))
    53  				Expect(healthchecks[2].ProcessType).To(Equal("worker"))
    54  			})
    55  		})
    56  	})
    57  
    58  	Describe("GetApplicationProcessHealthChecksByNameAndSpace", func() {
    59  		var (
    60  			warnings            Warnings
    61  			executeErr          error
    62  			processHealthChecks []ProcessHealthCheck
    63  		)
    64  
    65  		JustBeforeEach(func() {
    66  			processHealthChecks, warnings, executeErr = actor.GetApplicationProcessHealthChecksByNameAndSpace("some-app-name", "some-space-guid")
    67  		})
    68  
    69  		When("application does not exist", func() {
    70  			BeforeEach(func() {
    71  				fakeCloudControllerClient.GetApplicationsReturns(
    72  					[]resources.Application{},
    73  					ccv3.Warnings{"some-warning"},
    74  					nil,
    75  				)
    76  			})
    77  
    78  			It("returns the error and warnings", func() {
    79  				Expect(executeErr).To(Equal(actionerror.ApplicationNotFoundError{Name: "some-app-name"}))
    80  				Expect(warnings).To(ConsistOf("some-warning"))
    81  			})
    82  		})
    83  
    84  		When("getting application returns an error", func() {
    85  			var expectedErr error
    86  
    87  			BeforeEach(func() {
    88  				expectedErr = errors.New("some-error")
    89  				fakeCloudControllerClient.GetApplicationsReturns(
    90  					[]resources.Application{},
    91  					ccv3.Warnings{"some-warning"},
    92  					expectedErr,
    93  				)
    94  			})
    95  
    96  			It("returns the error and warnings", func() {
    97  				Expect(executeErr).To(Equal(expectedErr))
    98  				Expect(warnings).To(ConsistOf("some-warning"))
    99  			})
   100  		})
   101  
   102  		When("application exists", func() {
   103  			BeforeEach(func() {
   104  				fakeCloudControllerClient.GetApplicationsReturns(
   105  					[]resources.Application{
   106  						{
   107  							GUID: "some-app-guid",
   108  						},
   109  					},
   110  					ccv3.Warnings{"some-warning"},
   111  					nil,
   112  				)
   113  			})
   114  
   115  			When("getting application processes returns an error", func() {
   116  				var expectedErr error
   117  
   118  				BeforeEach(func() {
   119  					expectedErr = errors.New("some-error")
   120  					fakeCloudControllerClient.GetApplicationProcessesReturns(
   121  						[]ccv3.Process{},
   122  						ccv3.Warnings{"some-process-warning"},
   123  						expectedErr,
   124  					)
   125  				})
   126  
   127  				It("returns the error and warnings", func() {
   128  					Expect(executeErr).To(Equal(expectedErr))
   129  					Expect(warnings).To(ConsistOf("some-warning", "some-process-warning"))
   130  				})
   131  			})
   132  
   133  			When("application has processes", func() {
   134  				BeforeEach(func() {
   135  					fakeCloudControllerClient.GetApplicationProcessesReturns(
   136  						[]ccv3.Process{
   137  							{
   138  								GUID:                         "process-guid-1",
   139  								Type:                         "process-type-1",
   140  								HealthCheckType:              "health-check-type-1",
   141  								HealthCheckEndpoint:          "health-check-endpoint-1",
   142  								HealthCheckInvocationTimeout: 42,
   143  							},
   144  							{
   145  								GUID:                         "process-guid-2",
   146  								Type:                         "process-type-2",
   147  								HealthCheckType:              "health-check-type-2",
   148  								HealthCheckInvocationTimeout: 0,
   149  							},
   150  						},
   151  						ccv3.Warnings{"some-process-warning"},
   152  						nil,
   153  					)
   154  				})
   155  
   156  				It("returns health checks", func() {
   157  					Expect(executeErr).NotTo(HaveOccurred())
   158  					Expect(warnings).To(ConsistOf("some-warning", "some-process-warning"))
   159  					Expect(processHealthChecks).To(Equal([]ProcessHealthCheck{
   160  						{
   161  							ProcessType:       "process-type-1",
   162  							HealthCheckType:   "health-check-type-1",
   163  							Endpoint:          "health-check-endpoint-1",
   164  							InvocationTimeout: 42,
   165  						},
   166  						{
   167  							ProcessType:       "process-type-2",
   168  							HealthCheckType:   "health-check-type-2",
   169  							InvocationTimeout: 0,
   170  						},
   171  					}))
   172  				})
   173  			})
   174  		})
   175  	})
   176  })