github.com/joey-fossa/fossa-cli@v0.7.34-0.20190708193710-569f1e8679f0/api/fossa/tar_test.go (about)

     1  package fossa_test
     2  
     3  import (
     4  	"encoding/base64"
     5  	"log"
     6  	"os"
     7  	"testing"
     8  
     9  	"github.com/stretchr/testify/assert"
    10  
    11  	"github.com/fossas/fossa-cli/api/fossa"
    12  )
    13  
    14  func TestCreateTar(t *testing.T) {
    15  	tmp, hash, err := fossa.CreateTarball("testdata")
    16  	assert.NoError(t, err)
    17  	log.Printf("Hash: %#v", hash)
    18  
    19  	// The file matching this hash has been manually checked to make sure it's a
    20  	// correct, readable tarball with the correct contents.
    21  	assert.Equal(t, "h9NNNZQ7ascb5H06xpAc4A==", base64.StdEncoding.EncodeToString(hash))
    22  
    23  	if os.Getenv("KEEP_TMP") == "" {
    24  		err = os.Remove(tmp.Name())
    25  		assert.NoError(t, err)
    26  	} else {
    27  		log.Printf("Generated tarball at: %#v", tmp.Name())
    28  	}
    29  }