github.com/jfrog/jfrog-cli-go@v1.22.1-0.20200318093948-4826ef344ffd/artifactory/utils/golang/project/archive_test.go (about)

     1  package project
     2  
     3  import (
     4  	"bytes"
     5  	"os"
     6  	"path/filepath"
     7  	"reflect"
     8  	"testing"
     9  
    10  	"github.com/jfrog/jfrog-cli-go/utils/cliutils"
    11  	"github.com/jfrog/jfrog-cli-go/utils/log"
    12  	"github.com/jfrog/jfrog-cli-go/utils/tests"
    13  	"github.com/jfrog/jfrog-client-go/utils/io/fileutils/checksum"
    14  )
    15  
    16  func TestArchiveProject(t *testing.T) {
    17  	log.SetDefaultLogger()
    18  	if cliutils.IsWindows() {
    19  		t.Skip("Skipping archive test...")
    20  	}
    21  	pwd, err := os.Getwd()
    22  	if err != nil {
    23  		t.Error(err)
    24  	}
    25  
    26  	buff := &bytes.Buffer{}
    27  	if err != nil {
    28  		t.Error(err)
    29  	}
    30  	originalFolder := "test_.git_suffix"
    31  	baseDir, dotGitPath := tests.PrepareDotGitDir(t, originalFolder, "testdata")
    32  	err = archiveProject(buff, filepath.Join(pwd, "testdata"), "myproject.com/module/name", "v1.0.0")
    33  	if err != nil {
    34  		t.Error(err)
    35  	}
    36  	expected := map[checksum.Algorithm]string{checksum.MD5: "28617d6e74fce3dd2bab21b1bd65009b", checksum.SHA1: "410814fbf21afdfb9c5b550151a51c2e986447fa"}
    37  	actual, err := checksum.Calc(buff)
    38  	if err != nil {
    39  		t.Error(err)
    40  	}
    41  
    42  	if !reflect.DeepEqual(expected, actual) {
    43  		t.Errorf("Expecting: %v, Got: %v", expected, actual)
    44  	}
    45  	tests.RenamePath(dotGitPath, filepath.Join(baseDir, originalFolder), t)
    46  }