gopkg.in/openshift/source-to-image.v1@v1.2.0/pkg/test/git.go (about)

     1  package test
     2  
     3  import (
     4  	"os"
     5  
     6  	"github.com/openshift/source-to-image/pkg/scm/git"
     7  )
     8  
     9  // FakeGit provides a fake Git
    10  type FakeGit struct {
    11  	CloneSource *git.URL
    12  	CloneTarget string
    13  	CloneError  error
    14  
    15  	CheckoutRepo  string
    16  	CheckoutRef   string
    17  	CheckoutError error
    18  
    19  	SubmoduleInitRepo  string
    20  	SubmoduleInitError error
    21  
    22  	SubmoduleUpdateRepo      string
    23  	SubmoduleUpdateInit      bool
    24  	SubmoduleUpdateRecursive bool
    25  	SubmoduleUpdateError     error
    26  }
    27  
    28  // Clone clones the fake source Git repository to target directory
    29  func (f *FakeGit) Clone(source *git.URL, target string, c git.CloneConfig) error {
    30  	f.CloneSource = source
    31  	f.CloneTarget = target
    32  	return f.CloneError
    33  }
    34  
    35  // Checkout checkouts a ref in the fake Git repository
    36  func (f *FakeGit) Checkout(repo, ref string) error {
    37  	f.CheckoutRepo = repo
    38  	f.CheckoutRef = ref
    39  	return f.CheckoutError
    40  }
    41  
    42  // SubmoduleInit initializes / clones submodules.
    43  func (f *FakeGit) SubmoduleInit(repo string) error {
    44  	f.SubmoduleInitRepo = repo
    45  	return f.SubmoduleInitError
    46  }
    47  
    48  // SubmoduleUpdate checks out submodules to their correct version
    49  func (f *FakeGit) SubmoduleUpdate(repo string, init, recursive bool) error {
    50  	f.SubmoduleUpdateRepo = repo
    51  	f.SubmoduleUpdateRecursive = recursive
    52  	f.SubmoduleUpdateInit = init
    53  	return f.SubmoduleUpdateError
    54  }
    55  
    56  // LsTree returns a slice of os.FileInfo objects populated with the paths and
    57  // file modes of files known to Git.  This is used on Windows systems where the
    58  // executable mode metadata is lost on git checkout.
    59  func (f *FakeGit) LsTree(repo, ref string, recursive bool) ([]os.FileInfo, error) {
    60  	return []os.FileInfo{}, nil
    61  }
    62  
    63  // GetInfo retrieves the information about the source code and commit
    64  func (f *FakeGit) GetInfo(repo string) *git.SourceInfo {
    65  	return &git.SourceInfo{
    66  		Ref:      "master",
    67  		CommitID: "1bf4f04",
    68  		Location: "file:///foo",
    69  	}
    70  }