github.com/pf-qiu/concourse/v6@v6.7.3-0.20201207032516-1f455d73275f/atc/db/task_cache_factory_test.go (about)

     1  package db_test
     2  
     3  import (
     4  	"github.com/pf-qiu/concourse/v6/atc/db"
     5  
     6  	. "github.com/onsi/ginkgo"
     7  	. "github.com/onsi/gomega"
     8  )
     9  
    10  var _ = Describe("TaskCacheFactory", func() {
    11  
    12  	Describe("FindOrCreate", func() {
    13  		Context("when there is no existing task cache", func() {
    14  			It("creates resource cache in database", func() {
    15  				usedTaskCache, err := taskCacheFactory.FindOrCreate(
    16  					defaultJob.ID(),
    17  					"some-step",
    18  					"some-path",
    19  				)
    20  				Expect(err).ToNot(HaveOccurred())
    21  				Expect(usedTaskCache.ID()).ToNot(BeNil())
    22  			})
    23  		})
    24  
    25  		Context("when there is existing task cache", func() {
    26  			var (
    27  				usedTaskCache db.UsedTaskCache
    28  				err           error
    29  			)
    30  
    31  			BeforeEach(func() {
    32  				usedTaskCache, err = taskCacheFactory.FindOrCreate(
    33  					defaultJob.ID(),
    34  					"some-step",
    35  					"some-path",
    36  				)
    37  				Expect(err).ToNot(HaveOccurred())
    38  			})
    39  
    40  			It("creates a new task cache for another task", func() {
    41  				otherTaskCache, err := taskCacheFactory.FindOrCreate(
    42  					defaultJob.ID(),
    43  					"some-other-step",
    44  					"some-path",
    45  				)
    46  				Expect(err).ToNot(HaveOccurred())
    47  				Expect(otherTaskCache.ID()).ToNot(Equal(usedTaskCache.ID()))
    48  			})
    49  		})
    50  	})
    51  
    52  	Describe("Find", func() {
    53  		Context("when there is no existing task cache", func() {
    54  			It("returns no found", func() {
    55  				usedTaskCache, found, err := taskCacheFactory.Find(
    56  					defaultJob.ID(),
    57  					"some-step",
    58  					"some-path",
    59  				)
    60  				Expect(err).ToNot(HaveOccurred())
    61  				Expect(found).To(BeFalse())
    62  				Expect(usedTaskCache).To(BeNil())
    63  			})
    64  		})
    65  
    66  		Context("when there is existing task cache", func() {
    67  			var (
    68  				usedTaskCache db.UsedTaskCache
    69  				err           error
    70  			)
    71  
    72  			BeforeEach(func() {
    73  				usedTaskCache, err = taskCacheFactory.FindOrCreate(
    74  					defaultJob.ID(),
    75  					"some-step",
    76  					"some-path",
    77  				)
    78  				Expect(err).ToNot(HaveOccurred())
    79  			})
    80  
    81  			It("finds task cache in database", func() {
    82  				utc, found, err := taskCacheFactory.Find(defaultJob.ID(), "some-step", "some-path")
    83  				Expect(err).ToNot(HaveOccurred())
    84  				Expect(found).To(BeTrue())
    85  				Expect(utc.ID()).To(Equal(usedTaskCache.ID()))
    86  			})
    87  		})
    88  	})
    89  })