0
0
mirror of https://github.com/thegeeklab/wp-git-clone.git synced 2024-11-28 08:30:37 +00:00
wp-git-clone/git/clone_test.go

64 lines
984 B
Go
Raw Normal View History

2023-12-22 23:59:23 +00:00
package git
import (
"testing"
)
// TestFetch tests if the arguments to `git fetch` are constructed properly.
func TestFetch(t *testing.T) {
testdata := []struct {
ref string
tags bool
depth int
exp []string
}{
{
"refs/heads/master",
false,
0,
[]string{
"/usr/bin/git",
"fetch",
"origin",
"+refs/heads/master:",
},
},
{
"refs/heads/master",
false,
50,
[]string{
"/usr/bin/git",
"fetch",
"--depth=50",
"origin",
"+refs/heads/master:",
},
},
{
"refs/heads/master",
true,
100,
[]string{
"/usr/bin/git",
"fetch",
"--depth=100",
"origin",
"+refs/heads/master:",
},
},
}
for _, td := range testdata {
c := FetchSource(td.ref, td.depth, "")
2023-12-22 23:59:23 +00:00
if len(c.Args) != len(td.exp) {
t.Errorf("Expected: %s, got %s", td.exp, c.Args)
}
for i := range c.Args {
if c.Args[i] != td.exp[i] {
t.Errorf("Expected: %s, got %s", td.exp, c.Args)
}
}
}
}