github.com/jaypipes/ghw@v0.21.1/pkg/context/context_test.go (about)

     1  //
     2  // Use and distribution licensed under the Apache license version 2.
     3  //
     4  // See the COPYING file in the root project directory for full text.
     5  //
     6  
     7  package context_test
     8  
     9  import (
    10  	"os"
    11  	"testing"
    12  
    13  	"github.com/jaypipes/ghw/pkg/context"
    14  	"github.com/jaypipes/ghw/pkg/option"
    15  )
    16  
    17  const (
    18  	testDataSnapshot = "../snapshot/testdata.tar.gz"
    19  )
    20  
    21  // nolint: gocyclo
    22  func TestSnapshotContext(t *testing.T) {
    23  	ctx := context.New(option.WithSnapshot(option.SnapshotOptions{
    24  		Path: testDataSnapshot,
    25  	}))
    26  
    27  	var uncompressedDir string
    28  	err := ctx.Do(func() error {
    29  		uncompressedDir = ctx.Chroot
    30  		return nil
    31  	})
    32  
    33  	if uncompressedDir == "" {
    34  		t.Fatalf("Expected the uncompressed dir path to not be empty")
    35  	}
    36  	if err != nil {
    37  		t.Fatalf("Expected nil err, but got %v", err)
    38  	}
    39  	if _, err = os.Stat(uncompressedDir); !os.IsNotExist(err) {
    40  		t.Fatalf("Expected the uncompressed dir to be deleted: %s", uncompressedDir)
    41  	}
    42  }