github.com/franc20/ayesa_sap@v7.0.0-beta.28.0.20200124003224-302d4d52fa6c+incompatible/actor/v7action/application_feature_test.go (about)

     1  package v7action_test
     2  
     3  import (
     4  	"errors"
     5  	"time"
     6  
     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/clock/fakeclock"
    11  	. "github.com/onsi/ginkgo"
    12  	. "github.com/onsi/gomega"
    13  )
    14  
    15  var _ = Describe("Application Feature Actions", func() {
    16  	var (
    17  		actor                     *Actor
    18  		fakeCloudControllerClient *v7actionfakes.FakeCloudControllerClient
    19  		fakeConfig                *v7actionfakes.FakeConfig
    20  		fakeClock                 *fakeclock.FakeClock
    21  	)
    22  
    23  	BeforeEach(func() {
    24  		fakeCloudControllerClient = new(v7actionfakes.FakeCloudControllerClient)
    25  		fakeConfig = new(v7actionfakes.FakeConfig)
    26  		fakeClock = fakeclock.NewFakeClock(time.Now())
    27  		actor = NewActor(fakeCloudControllerClient, fakeConfig, nil, nil, fakeClock)
    28  	})
    29  
    30  	Describe("GetAppFeature", func() {
    31  		var (
    32  			appGUID    = "some-app-guid"
    33  			warnings   Warnings
    34  			executeErr error
    35  			appFeature ccv3.ApplicationFeature
    36  		)
    37  
    38  		JustBeforeEach(func() {
    39  			appFeature, warnings, executeErr = actor.GetAppFeature(appGUID, "ssh")
    40  		})
    41  		Context("Getting SSH", func() {
    42  			When("it succeeds", func() {
    43  				BeforeEach(func() {
    44  					fakeCloudControllerClient.GetAppFeatureReturns(
    45  						ccv3.ApplicationFeature{Name: "ssh", Enabled: true},
    46  						ccv3.Warnings{},
    47  						nil,
    48  					)
    49  				})
    50  
    51  				It("calls ccv3 to check current ssh ability", func() {
    52  					Expect(fakeCloudControllerClient.GetAppFeatureCallCount()).To(Equal(1))
    53  					appGuid, featureName := fakeCloudControllerClient.GetAppFeatureArgsForCall(0)
    54  					Expect(appGuid).To(Equal(appGUID))
    55  					Expect(featureName).To(Equal("ssh"))
    56  				})
    57  
    58  				It("returns an app feature", func() {
    59  					Expect(appFeature.Name).To(Equal("ssh"))
    60  					Expect(appFeature.Enabled).To(BeTrue())
    61  				})
    62  
    63  				When("desired enabled state is already, the current state", func() {
    64  					BeforeEach(func() {
    65  						fakeCloudControllerClient.GetAppFeatureReturns(
    66  							ccv3.ApplicationFeature{Enabled: true},
    67  							ccv3.Warnings{"some-ccv3-warning"},
    68  							nil,
    69  						)
    70  					})
    71  
    72  					It("returns a waring", func() {
    73  						Expect(warnings).To(ConsistOf("some-ccv3-warning"))
    74  					})
    75  				})
    76  			})
    77  
    78  			When("when the API layer call returns an error", func() {
    79  				BeforeEach(func() {
    80  					fakeCloudControllerClient.GetAppFeatureReturns(
    81  						ccv3.ApplicationFeature{Enabled: false},
    82  						ccv3.Warnings{"some-get-ssh-warning"},
    83  						errors.New("some-get-ssh-error"),
    84  					)
    85  				})
    86  
    87  				It("returns the error and prints warnings", func() {
    88  					Expect(executeErr).To(MatchError("some-get-ssh-error"))
    89  					Expect(warnings).To(ConsistOf("some-get-ssh-warning"))
    90  
    91  					Expect(fakeCloudControllerClient.GetAppFeatureCallCount()).To(Equal(1))
    92  				})
    93  			})
    94  		})
    95  
    96  	})
    97  
    98  	Describe("UpdateAppFeature", func() {
    99  		var (
   100  			app        = Application{Name: "some-app", GUID: "some-app-guid"}
   101  			enabled    = true
   102  			warnings   Warnings
   103  			executeErr error
   104  		)
   105  
   106  		JustBeforeEach(func() {
   107  			warnings, executeErr = actor.UpdateAppFeature(app, true, "ssh")
   108  		})
   109  		Context("Getting SSH", func() {
   110  			When("it succeeds", func() {
   111  				It("calls ccv3 to enable ssh", func() {
   112  					Expect(fakeCloudControllerClient.UpdateAppFeatureCallCount()).To(Equal(1))
   113  					actualApp, actualEnabled, featureName := fakeCloudControllerClient.UpdateAppFeatureArgsForCall(0)
   114  					Expect(actualApp).To(Equal(app.GUID))
   115  					Expect(actualEnabled).To(Equal(enabled))
   116  					Expect(featureName).To(Equal("ssh"))
   117  				})
   118  
   119  				When("the API layer call is successful", func() {
   120  					BeforeEach(func() {
   121  						fakeCloudControllerClient.UpdateAppFeatureReturns(ccv3.Warnings{"some-update-ssh-warning"}, nil)
   122  					})
   123  
   124  					It("does not error", func() {
   125  						Expect(executeErr).ToNot(HaveOccurred())
   126  						Expect(warnings).To(ConsistOf("some-update-ssh-warning"))
   127  					})
   128  				})
   129  			})
   130  
   131  			When("when the API layer call returns an error", func() {
   132  				BeforeEach(func() {
   133  					fakeCloudControllerClient.UpdateAppFeatureReturns(
   134  						ccv3.Warnings{"some-update-ssh-warning"},
   135  						errors.New("some-update-ssh-error"),
   136  					)
   137  				})
   138  
   139  				It("returns the error and prints warnings", func() {
   140  					Expect(executeErr).To(MatchError("some-update-ssh-error"))
   141  					Expect(warnings).To(ConsistOf("some-update-ssh-warning"))
   142  
   143  					Expect(fakeCloudControllerClient.UpdateAppFeatureCallCount()).To(Equal(1))
   144  				})
   145  			})
   146  		})
   147  	})
   148  
   149  	Describe("GetSSHEnabled", func() {
   150  		var (
   151  			appGUID    = "some-app-guid"
   152  			warnings   Warnings
   153  			executeErr error
   154  			sshEnabled ccv3.SSHEnabled
   155  		)
   156  
   157  		JustBeforeEach(func() {
   158  			sshEnabled, warnings, executeErr = actor.GetSSHEnabled(appGUID)
   159  		})
   160  		When("it succeeds", func() {
   161  			BeforeEach(func() {
   162  				fakeCloudControllerClient.GetSSHEnabledReturns(
   163  					ccv3.SSHEnabled{Reason: "some-reason", Enabled: true},
   164  					ccv3.Warnings{"some-ccv3-warning"},
   165  					nil,
   166  				)
   167  			})
   168  
   169  			It("calls ccv3 to check current ssh ability", func() {
   170  				Expect(fakeCloudControllerClient.GetSSHEnabledCallCount()).To(Equal(1))
   171  				appGuid := fakeCloudControllerClient.GetSSHEnabledArgsForCall(0)
   172  				Expect(appGuid).To(Equal(appGUID))
   173  			})
   174  
   175  			It("returns an sshEnabled", func() {
   176  				Expect(sshEnabled.Reason).To(Equal("some-reason"))
   177  				Expect(sshEnabled.Enabled).To(BeTrue())
   178  			})
   179  
   180  			It("returns a warning", func() {
   181  				Expect(warnings).To(ConsistOf("some-ccv3-warning"))
   182  			})
   183  
   184  			When("when it's disabled", func() {
   185  				BeforeEach(func() {
   186  					fakeCloudControllerClient.GetSSHEnabledReturns(
   187  						ccv3.SSHEnabled{Reason: "another-reason", Enabled: false},
   188  						ccv3.Warnings{"some-ccv3-warning"},
   189  						nil,
   190  					)
   191  				})
   192  
   193  				It("returns an sshEnabled", func() {
   194  					Expect(sshEnabled.Reason).To(Equal("another-reason"))
   195  					Expect(sshEnabled.Enabled).To(BeFalse())
   196  				})
   197  			})
   198  		})
   199  
   200  		When("when the API layer call returns an error", func() {
   201  			BeforeEach(func() {
   202  				fakeCloudControllerClient.GetSSHEnabledReturns(
   203  					ccv3.SSHEnabled{Reason: "some-third-reason", Enabled: false},
   204  					ccv3.Warnings{"some-get-ssh-warning"},
   205  					errors.New("some-get-ssh-error"),
   206  				)
   207  			})
   208  
   209  			It("returns the error and prints warnings", func() {
   210  				Expect(executeErr).To(MatchError("some-get-ssh-error"))
   211  				Expect(warnings).To(ConsistOf("some-get-ssh-warning"))
   212  
   213  				Expect(fakeCloudControllerClient.GetSSHEnabledCallCount()).To(Equal(1))
   214  			})
   215  		})
   216  	})
   217  })