github.com/pf-qiu/concourse/v6@v6.7.3-0.20201207032516-1f455d73275f/atc/exec/build/repository_test.go (about)

     1  package build_test
     2  
     3  import (
     4  	"github.com/pf-qiu/concourse/v6/atc/exec/build"
     5  	. "github.com/pf-qiu/concourse/v6/atc/exec/build"
     6  	"github.com/pf-qiu/concourse/v6/atc/runtime"
     7  	"github.com/pf-qiu/concourse/v6/atc/runtime/runtimefakes"
     8  
     9  	. "github.com/onsi/ginkgo"
    10  	. "github.com/onsi/gomega"
    11  )
    12  
    13  var _ = Describe("ArtifactRepository", func() {
    14  	var (
    15  		repo *Repository
    16  	)
    17  
    18  	BeforeEach(func() {
    19  		repo = NewRepository()
    20  	})
    21  
    22  	It("initially does not contain any artifacts", func() {
    23  		artifact, found := repo.ArtifactFor("first-artifact")
    24  		Expect(artifact).To(BeNil())
    25  		Expect(found).To(BeFalse())
    26  	})
    27  
    28  	Context("when a artifact is registered", func() {
    29  		var firstArtifact *runtimefakes.FakeArtifact
    30  
    31  		BeforeEach(func() {
    32  			firstArtifact = new(runtimefakes.FakeArtifact)
    33  			firstArtifact.IDReturns("some-first")
    34  			repo.RegisterArtifact("first-artifact", firstArtifact)
    35  		})
    36  
    37  		Describe("ArtifactFor", func() {
    38  			It("yields the artifact by the given name", func() {
    39  				artifact, found := repo.ArtifactFor("first-artifact")
    40  				Expect(artifact).To(Equal(firstArtifact))
    41  				Expect(found).To(BeTrue())
    42  			})
    43  
    44  			It("yields nothing for unregistered names", func() {
    45  				artifact, found := repo.ArtifactFor("bogus-artifact")
    46  				Expect(artifact).To(BeNil())
    47  				Expect(found).To(BeFalse())
    48  			})
    49  		})
    50  
    51  		Describe("NewLocalScope", func() {
    52  			var child *build.Repository
    53  
    54  			BeforeEach(func() {
    55  				child = repo.NewLocalScope()
    56  			})
    57  
    58  			It("contains the same artifacts as the parent", func() {
    59  				Expect(child.AsMap()).To(Equal(repo.AsMap()))
    60  			})
    61  
    62  			It("maintains a reference to the parent", func() {
    63  				Expect(child.Parent()).To(Equal(repo))
    64  			})
    65  
    66  			Context("when an artifact is registered", func() {
    67  				var secondArtifact *runtimefakes.FakeArtifact
    68  
    69  				BeforeEach(func() {
    70  					secondArtifact = new(runtimefakes.FakeArtifact)
    71  					secondArtifact.IDReturns("some-second")
    72  
    73  					child.RegisterArtifact("second-artifact", secondArtifact)
    74  				})
    75  
    76  				It("is present in the child but not the parent", func() {
    77  					Expect(child.AsMap()).To(Equal(map[build.ArtifactName]runtime.Artifact{
    78  						"first-artifact":  firstArtifact,
    79  						"second-artifact": secondArtifact,
    80  					}))
    81  
    82  					Expect(repo.AsMap()).To(Equal(map[build.ArtifactName]runtime.Artifact{
    83  						"first-artifact": firstArtifact,
    84  					}))
    85  				})
    86  			})
    87  
    88  			Context("when an artifact is overridden", func() {
    89  				var firstPrimeArtifact *runtimefakes.FakeArtifact
    90  
    91  				BeforeEach(func() {
    92  					firstPrimeArtifact = new(runtimefakes.FakeArtifact)
    93  					firstPrimeArtifact.IDReturns("some-second")
    94  
    95  					child.RegisterArtifact("first-artifact", firstPrimeArtifact)
    96  				})
    97  
    98  				It("is overridden in the child but not the parent", func() {
    99  					Expect(child.AsMap()).To(Equal(map[build.ArtifactName]runtime.Artifact{
   100  						"first-artifact": firstPrimeArtifact,
   101  					}))
   102  
   103  					Expect(repo.AsMap()).To(Equal(map[build.ArtifactName]runtime.Artifact{
   104  						"first-artifact": firstArtifact,
   105  					}))
   106  				})
   107  			})
   108  		})
   109  
   110  		Context("when a second artifact is registered", func() {
   111  			var secondArtifact *runtimefakes.FakeArtifact
   112  
   113  			BeforeEach(func() {
   114  				secondArtifact = new(runtimefakes.FakeArtifact)
   115  				secondArtifact.IDReturns("some-second")
   116  
   117  				repo.RegisterArtifact("second-artifact", secondArtifact)
   118  			})
   119  
   120  			Describe("AsMap", func() {
   121  				It("returns all artifacts", func() {
   122  					Expect(repo.AsMap()).To(Equal(map[build.ArtifactName]runtime.Artifact{
   123  						"first-artifact":  firstArtifact,
   124  						"second-artifact": secondArtifact,
   125  					}))
   126  				})
   127  			})
   128  
   129  			Describe("ArtifactFor", func() {
   130  				It("yields the first artifact by the given name", func() {
   131  					actualArtifact, found := repo.ArtifactFor("first-artifact")
   132  					Expect(actualArtifact).To(Equal(firstArtifact))
   133  					Expect(found).To(BeTrue())
   134  				})
   135  
   136  				It("yields the second artifact by the given name", func() {
   137  					actualArtifact, found := repo.ArtifactFor("second-artifact")
   138  					Expect(actualArtifact).To(Equal(secondArtifact))
   139  					Expect(found).To(BeTrue())
   140  				})
   141  
   142  				It("yields nothing for unregistered names", func() {
   143  					actualArtifact, found := repo.ArtifactFor("bogus-artifact")
   144  					Expect(actualArtifact).To(BeNil())
   145  					Expect(found).To(BeFalse())
   146  				})
   147  			})
   148  		})
   149  	})
   150  })