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

     1  package artifactstest
     2  
     3  import (
     4  	"os"
     5  	"path/filepath"
     6  	"testing"
     7  
     8  	"github.com/benchkram/bob/bob"
     9  	"github.com/benchkram/bob/bob/global"
    10  	"github.com/benchkram/bob/pkg/boblog"
    11  	"github.com/benchkram/bob/pkg/buildinfostore"
    12  	"github.com/benchkram/bob/pkg/store"
    13  	"github.com/benchkram/bob/test/setup"
    14  
    15  	. "github.com/onsi/ginkgo"
    16  	. "github.com/onsi/gomega"
    17  )
    18  
    19  // Test case overview for target invalidation with artifacts in the local store.
    20  // Input change not included, should not change for those tests.
    21  //
    22  // dne = does not exist
    23  //
    24  //    BUILDINFO          TARGET       LOCAL_ARTIFACT
    25  
    26  // Following cases are tested in nobuildinfo_test.go
    27  // 1  dne                unchanged    dne                  | 0 0 0 |     =>   rebuild (buildinfostore cleaned?)
    28  // 2  dne                unchanged    exists               | 0 0 1 |     =>   no-rebuild-required (update target from artifact)
    29  // 3  dne                changed/dne  dne                  | 0 1 0 |     =>   rebuild (buildinfostore cleaned?)
    30  // 4  dne                changed/dne  exists               | 0 1 1 |     =>   no-rebuild-required (update target from artifact)
    31  //
    32  // Following cases are tested in artifact_test.go
    33  // 5  exists             unchanged    dne                  | 1 0 0 |     =>   rebuild-required (to assure the target is correctly pushed to the local store)
    34  // 6  exists             unchanged    exists               | 1 0 1 |     =>   no-rebuild-required
    35  // 7  exists             changed      dne                  | 1 1 0 |     =>   rebuild
    36  // 8  exists             changed      exists               | 1 1 1 |     =>   no-rebuild-required (update target from artifact)
    37  //
    38  
    39  var (
    40  	dir         string
    41  	artifactDir string
    42  
    43  	artifactStore  store.Store
    44  	buildinfoStore buildinfostore.Store
    45  
    46  	cleanup func() error
    47  
    48  	b *bob.B
    49  
    50  	bNoCache *bob.B
    51  )
    52  
    53  // reset base test dir to it's
    54  // initial state.
    55  func reset() error {
    56  	err := os.RemoveAll(dir)
    57  	if err != nil {
    58  		return err
    59  	}
    60  	return os.MkdirAll(dir, 0777)
    61  }
    62  
    63  var _ = BeforeSuite(func() {
    64  	boblog.SetLogLevel(10)
    65  
    66  	var err error
    67  	var storageDir string
    68  	dir, storageDir, cleanup, err = setup.TestDirs("artifacts")
    69  	Expect(err).NotTo(HaveOccurred())
    70  	artifactDir = filepath.Join(storageDir, global.BobCacheArtifactsDir)
    71  
    72  	err = os.Chdir(dir)
    73  	Expect(err).NotTo(HaveOccurred())
    74  
    75  	// objects using the local filesystem for caching and persistent.
    76  	// Initialized on a temporary location to avoid interference with
    77  	// a local bob installation.
    78  	artifactStore, err = bob.Filestore(storageDir)
    79  	Expect(err).NotTo(HaveOccurred())
    80  	buildinfoStore, err = bob.BuildinfoStore(storageDir)
    81  	Expect(err).NotTo(HaveOccurred())
    82  	nixBuilder, err := bob.NixBuilder(storageDir)
    83  	Expect(err).NotTo(HaveOccurred())
    84  
    85  	b, err = bob.Bob(
    86  		bob.WithDir(dir),
    87  		bob.WithFilestore(artifactStore),
    88  		bob.WithBuildinfoStore(buildinfoStore),
    89  		bob.WithNixBuilder(nixBuilder),
    90  	)
    91  	Expect(err).NotTo(HaveOccurred())
    92  
    93  	bNoCache, err = bob.BobWithBaseStoreDir(
    94  		storageDir,
    95  		bob.WithDir(dir),
    96  		bob.WithCachingEnabled(false),
    97  		bob.WithNixBuilder(nixBuilder),
    98  	)
    99  	Expect(err).NotTo(HaveOccurred())
   100  })
   101  
   102  var _ = AfterSuite(func() {
   103  	err := cleanup()
   104  	Expect(err).NotTo(HaveOccurred())
   105  })
   106  
   107  func TestArtifact(t *testing.T) {
   108  	RegisterFailHandler(Fail)
   109  	RunSpecs(t, "artifacts suite")
   110  }