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

     1  package db_test
     2  
     3  import (
     4  	"github.com/pf-qiu/concourse/v6/atc/db"
     5  	. "github.com/onsi/ginkgo"
     6  	. "github.com/onsi/gomega"
     7  )
     8  
     9  var _ = Describe("WorkerArtifactLifecycle", func() {
    10  	var workerArtifactLifecycle db.WorkerArtifactLifecycle
    11  
    12  	BeforeEach(func() {
    13  		workerArtifactLifecycle = db.NewArtifactLifecycle(dbConn)
    14  	})
    15  
    16  	Describe("RemoveExpiredArtifacts", func() {
    17  		JustBeforeEach(func() {
    18  			err := workerArtifactLifecycle.RemoveExpiredArtifacts()
    19  			Expect(err).ToNot(HaveOccurred())
    20  		})
    21  
    22  		Context("removes artifacts created more than 12 hours ago", func() {
    23  
    24  			BeforeEach(func() {
    25  				_, err := dbConn.Exec("INSERT INTO worker_artifacts(name, created_at) VALUES('some-name', NOW() - '13 hours'::interval)")
    26  				Expect(err).ToNot(HaveOccurred())
    27  			})
    28  
    29  			It("removes the record", func() {
    30  				var count int
    31  				err := dbConn.QueryRow("SELECT count(*) from worker_artifacts").Scan(&count)
    32  				Expect(err).ToNot(HaveOccurred())
    33  				Expect(count).To(Equal(0))
    34  			})
    35  		})
    36  
    37  		Context("keeps artifacts for 12 hours", func() {
    38  
    39  			BeforeEach(func() {
    40  				_, err := dbConn.Exec("INSERT INTO worker_artifacts(name, created_at) VALUES('some-name', NOW() - '13 hours'::interval)")
    41  				Expect(err).ToNot(HaveOccurred())
    42  
    43  				_, err = dbConn.Exec("INSERT INTO worker_artifacts(name, created_at) VALUES('some-other-name', NOW())")
    44  				Expect(err).ToNot(HaveOccurred())
    45  			})
    46  
    47  			It("does not remove the record", func() {
    48  				var count int
    49  				err := dbConn.QueryRow("SELECT count(*) from worker_artifacts").Scan(&count)
    50  				Expect(err).ToNot(HaveOccurred())
    51  				Expect(count).To(Equal(1))
    52  			})
    53  		})
    54  	})
    55  })