github.com/chenbh/concourse/v6@v6.4.2/atc/resource/resource_get_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  	"github.com/onsi/gomega/gbytes"
    15  )
    16  
    17  var _ = Describe("Resource Get", func() {
    18  	var (
    19  		ctx             context.Context
    20  		someProcessSpec runtime.ProcessSpec
    21  		fakeRunnable    runtimefakes.FakeRunner
    22  
    23  		getVersionResult runtime.VersionResult
    24  
    25  		source  atc.Source
    26  		params  atc.Params
    27  		version atc.Version
    28  
    29  		resource resource.Resource
    30  
    31  		getErr error
    32  	)
    33  
    34  	BeforeEach(func() {
    35  		ctx = context.Background()
    36  
    37  		source = atc.Source{"some": "source"}
    38  		version = atc.Version{"some": "version"}
    39  		params = atc.Params{"some": "params"}
    40  
    41  		someProcessSpec.Path = "some/fake/path"
    42  		someProcessSpec.Args = []string{"first-arg", "some-other-arg"}
    43  		someProcessSpec.StderrWriter = gbytes.NewBuffer()
    44  
    45  		resource = resourceFactory.NewResource(source, params, version)
    46  
    47  	})
    48  
    49  	JustBeforeEach(func() {
    50  		getVersionResult, getErr = resource.Get(ctx, someProcessSpec, &fakeRunnable)
    51  	})
    52  
    53  	Context("when Runnable -> RunScript succeeds", func() {
    54  		BeforeEach(func() {
    55  			fakeRunnable.RunScriptReturns(nil)
    56  		})
    57  
    58  		It("Invokes Runnable -> RunScript with the correct arguments", func() {
    59  			actualCtx, actualSpecPath, actualArgs,
    60  				actualInput, actualVersionResultRef, actualSpecStdErrWriter,
    61  				actualRecoverableBool := fakeRunnable.RunScriptArgsForCall(0)
    62  
    63  			signature, err := resource.Signature()
    64  			Expect(err).ToNot(HaveOccurred())
    65  
    66  			Expect(actualCtx).To(Equal(ctx))
    67  			Expect(actualSpecPath).To(Equal(someProcessSpec.Path))
    68  			Expect(actualArgs).To(Equal(someProcessSpec.Args))
    69  			Expect(actualInput).To(Equal(signature))
    70  			Expect(actualVersionResultRef).To(Equal(&getVersionResult))
    71  			Expect(actualSpecStdErrWriter).To(Equal(someProcessSpec.StderrWriter))
    72  			Expect(actualRecoverableBool).To(BeTrue())
    73  		})
    74  
    75  		It("doesnt return an error", func() {
    76  			Expect(getErr).To(BeNil())
    77  		})
    78  	})
    79  
    80  	Context("when Runnable -> RunScript returns an error", func() {
    81  		var disasterErr = errors.New("there was an issue")
    82  		BeforeEach(func() {
    83  			fakeRunnable.RunScriptReturns(disasterErr)
    84  		})
    85  		It("returns the error", func() {
    86  			Expect(getErr).To(Equal(disasterErr))
    87  		})
    88  	})
    89  
    90  })