github.com/benchkram/bob@v0.0.0-20240314204020-b7a57f2f9be9/test/e2e/artifacts/artifacts_no_cache_test.go (about)

     1  package artifactstest
     2  
     3  import (
     4  	"context"
     5  	"os"
     6  
     7  	"github.com/benchkram/bob/bob"
     8  	"github.com/benchkram/bob/bob/playbook"
     9  	"github.com/benchkram/errz"
    10  	. "github.com/onsi/ginkgo"
    11  	. "github.com/onsi/gomega"
    12  )
    13  
    14  var _ = Describe("Test artifact and target on no cache build", func() {
    15  	Context("in a fresh playground", func() {
    16  
    17  		It("should initialize bob playground", func() {
    18  			Expect(bob.CreatePlayground(bob.PlaygroundOptions{Dir: dir})).NotTo(HaveOccurred())
    19  		})
    20  
    21  		It("should build both with and without cache", func() {
    22  			ctx := context.Background()
    23  
    24  			err := bNoCache.Build(ctx, "build")
    25  			errz.Log(err)
    26  
    27  			Expect(err).NotTo(HaveOccurred())
    28  		})
    29  
    30  		It("no artifacts should be created", func() {
    31  			fs, err := os.ReadDir(artifactDir)
    32  			Expect(err).NotTo(HaveOccurred())
    33  			Expect(len(fs)).To(Equal(0))
    34  		})
    35  
    36  		It("should rebuild and create a new artifact for always-build without no-cache", func() {
    37  			// b and bNoCache uses the same dir, so this should
    38  			// work without running b.Build first
    39  			state, err := buildTask(b, bob.BuildAlwaysTargetName)
    40  			Expect(err).NotTo(HaveOccurred())
    41  			Expect(state.State()).To(Equal(playbook.StateCompleted))
    42  
    43  			fs, err := os.ReadDir(artifactDir)
    44  			Expect(err).NotTo(HaveOccurred())
    45  			Expect(len(fs)).To(Equal(1))
    46  
    47  			artifactID := fs[0].Name()
    48  			err = artifactRemove(artifactID)
    49  			Expect(err).NotTo(HaveOccurred())
    50  		})
    51  
    52  		It("should rebuild and create no artifact for always-build with no-cache", func() {
    53  			ctx := context.Background()
    54  			err := bNoCache.Build(ctx, bob.BuildAlwaysTargetName)
    55  			Expect(err).NotTo(HaveOccurred())
    56  
    57  			fs, err := os.ReadDir(artifactDir)
    58  			Expect(err).NotTo(HaveOccurred())
    59  			Expect(len(fs)).To(Equal(0))
    60  		})
    61  
    62  		It("should rebuild and create no artifact for all task build with no-cache", func() {
    63  			ctx := context.Background()
    64  			err := bNoCache.Build(ctx, bob.BuildAllTargetName)
    65  			Expect(err).NotTo(HaveOccurred())
    66  
    67  			fs, err := os.ReadDir(artifactDir)
    68  			Expect(err).NotTo(HaveOccurred())
    69  			Expect(len(fs)).To(Equal(0))
    70  		})
    71  
    72  		It("cleanup", func() {
    73  			// b and bNoCache uses the same dir, so this should
    74  			// so this cleans directory for both build task
    75  			err := bNoCache.CleanBuildInfoStore()
    76  			Expect(err).NotTo(HaveOccurred())
    77  
    78  			err = bNoCache.CleanLocalStore()
    79  			Expect(err).NotTo(HaveOccurred())
    80  
    81  			err = reset()
    82  			Expect(err).NotTo(HaveOccurred())
    83  		})
    84  	})
    85  })