github.com/chenbh/concourse/v6@v6.4.2/atc/resource/resource_check_test.go (about)

     1  package resource_test
     2  
     3  import (
     4  	"context"
     5  	"errors"
     6  
     7  	"github.com/chenbh/concourse/v6/atc"
     8  	"github.com/chenbh/concourse/v6/atc/resource"
     9  	"github.com/chenbh/concourse/v6/atc/runtime"
    10  	"github.com/chenbh/concourse/v6/atc/runtime/runtimefakes"
    11  
    12  	. "github.com/onsi/ginkgo"
    13  	. "github.com/onsi/gomega"
    14  )
    15  
    16  var _ = Describe("Resource Check", func() {
    17  	var (
    18  		ctx             context.Context
    19  		someProcessSpec runtime.ProcessSpec
    20  		fakeRunnable    runtimefakes.FakeRunner
    21  
    22  		checkVersions []atc.Version
    23  
    24  		source  atc.Source
    25  		params  atc.Params
    26  		version atc.Version
    27  
    28  		resource resource.Resource
    29  
    30  		checkErr error
    31  	)
    32  
    33  	BeforeEach(func() {
    34  		ctx = context.Background()
    35  
    36  		source = atc.Source{"some": "source"}
    37  		version = atc.Version{"some": "version"}
    38  		params = atc.Params{"some": "params"}
    39  
    40  		someProcessSpec.Path = "some/fake/path"
    41  
    42  		resource = resourceFactory.NewResource(source, params, version)
    43  	})
    44  
    45  	JustBeforeEach(func() {
    46  		checkVersions, checkErr = resource.Check(ctx, someProcessSpec, &fakeRunnable)
    47  	})
    48  
    49  	Context("when Runnable -> RunScript succeeds", func() {
    50  		BeforeEach(func() {
    51  			fakeRunnable.RunScriptReturns(nil)
    52  		})
    53  
    54  		It("Invokes Runnable -> RunScript with the correct arguments", func() {
    55  			actualCtx, actualSpecPath, actualArgs,
    56  				actualInput, actualVersionResultRef, actualSpecStdErrWriter,
    57  				actualRecoverableBool := fakeRunnable.RunScriptArgsForCall(0)
    58  
    59  			signature, err := resource.Signature()
    60  			Expect(err).ToNot(HaveOccurred())
    61  
    62  			Expect(actualCtx).To(Equal(ctx))
    63  			Expect(actualSpecPath).To(Equal(someProcessSpec.Path))
    64  			Expect(actualArgs).To(BeNil())
    65  			Expect(actualInput).To(Equal(signature))
    66  			Expect(actualVersionResultRef).To(Equal(&checkVersions))
    67  			Expect(actualSpecStdErrWriter).To(BeNil())
    68  			Expect(actualRecoverableBool).To(BeFalse())
    69  		})
    70  
    71  		It("doesnt return an error", func() {
    72  			Expect(checkErr).To(BeNil())
    73  		})
    74  	})
    75  
    76  	Context("when Runnable -> RunScript returns an error", func() {
    77  		var disasterErr = errors.New("there was an issue")
    78  		BeforeEach(func() {
    79  			fakeRunnable.RunScriptReturns(disasterErr)
    80  		})
    81  		It("returns the error", func() {
    82  			Expect(checkErr).To(Equal(disasterErr))
    83  		})
    84  	})
    85  
    86  })