github.com/cloudfoundry-incubator/stembuild@v0.0.0-20211223202937-5b61d62226c6/construct/winrm_connection_validator_test.go (about)

     1  package construct_test
     2  
     3  import (
     4  	"errors"
     5  	//"github.com/cloudfoundry-incubator/stembuild/construct"
     6  	"github.com/cloudfoundry-incubator/stembuild/construct"
     7  	"github.com/cloudfoundry-incubator/stembuild/remotemanager/remotemanagerfakes"
     8  	. "github.com/onsi/ginkgo"
     9  	. "github.com/onsi/gomega"
    10  	//. "github.com/onsi/gomega"
    11  )
    12  
    13  var _ = Describe("VMConnectionValidator", func() {
    14  	var (
    15  		validator         *construct.WinRMConnectionValidator
    16  		fakeRemoteManager *remotemanagerfakes.FakeRemoteManager
    17  	)
    18  
    19  	BeforeEach(func() {
    20  		fakeRemoteManager = &remotemanagerfakes.FakeRemoteManager{}
    21  
    22  		validator = &construct.WinRMConnectionValidator{
    23  			RemoteManager: fakeRemoteManager,
    24  		}
    25  	})
    26  
    27  	Describe("Validate connection to the VM", func() {
    28  		It("can reach VM and can login to VM", func() {
    29  			err := validator.Validate()
    30  
    31  			Expect(err).NotTo(HaveOccurred())
    32  			Expect(fakeRemoteManager.CanReachVMCallCount()).To(Equal(1))
    33  			Expect(fakeRemoteManager.CanLoginVMCallCount()).To(Equal(1))
    34  		})
    35  
    36  		It("return an error when it cannot reach the VM", func() {
    37  			fakeRemoteManager.CanReachVMReturns(errors.New("could not reach vm"))
    38  			err := validator.Validate()
    39  
    40  			Expect(err).To(HaveOccurred())
    41  			Expect(fakeRemoteManager.CanReachVMCallCount()).To(Equal(1))
    42  			Expect(fakeRemoteManager.CanLoginVMCallCount()).To(Equal(0))
    43  		})
    44  
    45  		It("return an error when it cannot log into the VM", func() {
    46  			fakeRemoteManager.CanLoginVMReturns(errors.New("login error"))
    47  
    48  			err := validator.Validate()
    49  			Expect(err).To(HaveOccurred())
    50  			Expect(err.Error()).To(ContainSubstring(errors.New("login error").Error()))
    51  
    52  			Expect(fakeRemoteManager.CanReachVMCallCount()).To(Equal(1))
    53  			Expect(fakeRemoteManager.CanLoginVMCallCount()).To(Equal(1))
    54  		})
    55  	})
    56  
    57  })