github.com/openshift/source-to-image@v1.4.1-0.20240516041539-bf52fc02204e/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/openshift/source-to-image/pkg/api"
     9  	"github.com/openshift/source-to-image/pkg/scm/git"
    10  	testcmd "github.com/openshift/source-to-image/pkg/test/cmd"
    11  	testfs "github.com/openshift/source-to-image/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#ref1"),
    22  		ContextDir:       "subdir",
    23  		IgnoreSubmodules: true,
    24  	}
    25  	info, err := c.Download(fakeConfig)
    26  	if err != nil {
    27  		t.Errorf("%v", err)
    28  	}
    29  	if info == nil {
    30  		t.Fatalf("Expected info to be not nil")
    31  	}
    32  	if filepath.ToSlash(fs.CopySource) != "upload/tmp/subdir" {
    33  		t.Errorf("The source directory should be 'upload/tmp/subdir', it is %v", fs.CopySource)
    34  	}
    35  	if filepath.ToSlash(fs.CopyDest) != "upload/src" {
    36  		t.Errorf("The target directory should be 'upload/src', it is %v", fs.CopyDest)
    37  	}
    38  	if filepath.ToSlash(fs.RemoveDirName) != "upload/tmp" {
    39  		t.Errorf("Expected to remove the upload/tmp directory")
    40  	}
    41  	if !reflect.DeepEqual(cr.Args, []string{"checkout", "--quiet", "ref1"}) {
    42  		t.Errorf("Unexpected command arguments: %#v", cr.Args)
    43  	}
    44  }