kubesphere.io/s2irun@v3.2.1+incompatible/pkg/scm/downloaders/git/clone_test.go (about)

     1  package git
     2  
     3  import (
     4  	"path/filepath"
     5  	"reflect"
     6  	"testing"
     7  
     8  	"github.com/kubesphere/s2irun/pkg/api"
     9  	"github.com/kubesphere/s2irun/pkg/scm/git"
    10  	testcmd "github.com/kubesphere/s2irun/pkg/test/cmd"
    11  	testfs "github.com/kubesphere/s2irun/pkg/test/fs"
    12  )
    13  
    14  func TestCloneWithContext(t *testing.T) {
    15  	fs := &testfs.FakeFileSystem{}
    16  	cr := &testcmd.FakeCmdRunner{}
    17  	gh := git.New(fs, cr)
    18  	c := &Clone{gh, fs}
    19  
    20  	fakeConfig := &api.Config{
    21  		Source:           git.MustParse("https://foo/bar.git"),
    22  		ContextDir:       "subdir",
    23  		IgnoreSubmodules: true,
    24  		RevisionId:       "ref1",
    25  	}
    26  	info, err := c.Download(fakeConfig)
    27  	if err != nil {
    28  		t.Errorf("%v", err)
    29  	}
    30  	if info == nil {
    31  		t.Fatalf("Expected info to be not nil")
    32  	}
    33  	if filepath.ToSlash(fs.CopySource) != "upload/tmp/subdir" {
    34  		t.Errorf("The source directory should be 'upload/tmp/subdir', it is %v", fs.CopySource)
    35  	}
    36  	if filepath.ToSlash(fs.CopyDest) != "upload/src" {
    37  		t.Errorf("The target directory should be 'upload/src', it is %v", fs.CopyDest)
    38  	}
    39  	if filepath.ToSlash(fs.RemoveDirName) != "upload/tmp" {
    40  		t.Errorf("Expected to remove the upload/tmp directory")
    41  	}
    42  	if !reflect.DeepEqual(cr.Args, []string{"checkout", "ref1"}) {
    43  		t.Errorf("Unexpected command arguments: %#v", cr.Args)
    44  	}
    45  }