2023-12-22 23:59:23 +00:00
|
|
|
package git
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2024-05-06 18:30:18 +00:00
|
|
|
|
2024-05-06 19:14:04 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
2023-12-22 23:59:23 +00:00
|
|
|
)
|
|
|
|
|
2024-05-06 18:30:18 +00:00
|
|
|
func TestFetchSource(t *testing.T) {
|
2023-12-22 23:59:23 +00:00
|
|
|
testdata := []struct {
|
2024-05-06 18:30:18 +00:00
|
|
|
name string
|
|
|
|
repo *Repository
|
2023-12-22 23:59:23 +00:00
|
|
|
tags bool
|
|
|
|
depth int
|
2024-05-06 18:30:18 +00:00
|
|
|
want []string
|
2023-12-22 23:59:23 +00:00
|
|
|
}{
|
|
|
|
{
|
2024-05-06 18:30:18 +00:00
|
|
|
name: "fetch main without tags",
|
|
|
|
repo: &Repository{
|
|
|
|
CommitRef: "refs/heads/main",
|
|
|
|
},
|
|
|
|
tags: false,
|
|
|
|
depth: 0,
|
|
|
|
want: []string{
|
|
|
|
gitBin,
|
2023-12-22 23:59:23 +00:00
|
|
|
"fetch",
|
|
|
|
"origin",
|
2024-05-06 18:30:18 +00:00
|
|
|
"+refs/heads/main:",
|
2023-12-22 23:59:23 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2024-05-06 18:30:18 +00:00
|
|
|
name: "fetch main without tags with depth",
|
|
|
|
repo: &Repository{
|
|
|
|
CommitRef: "refs/heads/main",
|
|
|
|
Depth: 50,
|
|
|
|
},
|
|
|
|
tags: false,
|
|
|
|
depth: 50,
|
|
|
|
want: []string{
|
|
|
|
gitBin,
|
2023-12-22 23:59:23 +00:00
|
|
|
"fetch",
|
|
|
|
"--depth=50",
|
|
|
|
"origin",
|
2024-05-06 18:30:18 +00:00
|
|
|
"+refs/heads/main:",
|
2023-12-22 23:59:23 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2024-05-06 18:30:18 +00:00
|
|
|
name: "fetch main with tags and depth",
|
|
|
|
repo: &Repository{
|
|
|
|
CommitRef: "refs/heads/main",
|
|
|
|
Depth: 100,
|
|
|
|
},
|
|
|
|
tags: true,
|
|
|
|
depth: 100,
|
|
|
|
want: []string{
|
|
|
|
gitBin,
|
2023-12-22 23:59:23 +00:00
|
|
|
"fetch",
|
|
|
|
"--depth=100",
|
|
|
|
"origin",
|
2024-05-06 18:30:18 +00:00
|
|
|
"+refs/heads/main:",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range testdata {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
cmd := tt.repo.FetchSource(tt.repo.CommitRef)
|
2024-05-06 19:14:04 +00:00
|
|
|
assert.Equal(t, tt.want, cmd.Args)
|
2024-05-06 18:30:18 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestFetchTags(t *testing.T) {
|
|
|
|
testdata := []struct {
|
|
|
|
name string
|
|
|
|
repo *Repository
|
|
|
|
tags bool
|
|
|
|
depth int
|
|
|
|
want []string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "fetch tags",
|
|
|
|
repo: &Repository{},
|
|
|
|
tags: true,
|
|
|
|
want: []string{
|
|
|
|
gitBin,
|
|
|
|
"fetch",
|
|
|
|
"--tags",
|
|
|
|
"--quiet",
|
|
|
|
"origin",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range testdata {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
cmd := tt.repo.FetchTags()
|
2024-05-06 19:14:04 +00:00
|
|
|
assert.Equal(t, tt.want, cmd.Args)
|
2024-05-06 18:30:18 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestFetchLFS(t *testing.T) {
|
|
|
|
testdata := []struct {
|
|
|
|
name string
|
|
|
|
repo *Repository
|
|
|
|
want []string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "fetch LFS",
|
|
|
|
repo: &Repository{},
|
|
|
|
want: []string{
|
|
|
|
gitBin,
|
|
|
|
"lfs",
|
|
|
|
"fetch",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range testdata {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
cmd := tt.repo.FetchLFS()
|
2024-05-06 19:14:04 +00:00
|
|
|
assert.Equal(t, tt.want, cmd.Args)
|
2024-05-06 18:30:18 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCheckoutHead(t *testing.T) {
|
|
|
|
testdata := []struct {
|
|
|
|
name string
|
|
|
|
repo *Repository
|
|
|
|
want []string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "checkout head",
|
|
|
|
repo: &Repository{},
|
|
|
|
want: []string{
|
|
|
|
gitBin,
|
|
|
|
"checkout",
|
|
|
|
"--force",
|
|
|
|
"--quiet",
|
|
|
|
"FETCH_HEAD",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range testdata {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
cmd := tt.repo.CheckoutHead()
|
2024-05-06 19:14:04 +00:00
|
|
|
assert.Equal(t, tt.want, cmd.Args)
|
2024-05-06 18:30:18 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCheckoutSha(t *testing.T) {
|
|
|
|
testdata := []struct {
|
|
|
|
name string
|
|
|
|
repo *Repository
|
|
|
|
want []string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "checkout sha",
|
|
|
|
repo: &Repository{
|
|
|
|
CommitSha: "abcd1234",
|
|
|
|
},
|
|
|
|
want: []string{
|
|
|
|
gitBin,
|
|
|
|
"reset",
|
|
|
|
"--hard",
|
|
|
|
"--quiet",
|
|
|
|
"abcd1234",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range testdata {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
cmd := tt.repo.CheckoutSha()
|
2024-05-06 19:14:04 +00:00
|
|
|
assert.Equal(t, tt.want, cmd.Args)
|
2024-05-06 18:30:18 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCheckoutLFS(t *testing.T) {
|
|
|
|
testdata := []struct {
|
|
|
|
name string
|
|
|
|
repo *Repository
|
|
|
|
want []string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "checkout LFS with no arguments",
|
|
|
|
repo: &Repository{},
|
|
|
|
want: []string{
|
|
|
|
gitBin,
|
|
|
|
"lfs",
|
|
|
|
"checkout",
|
2023-12-22 23:59:23 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2024-05-06 18:30:18 +00:00
|
|
|
for _, tt := range testdata {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
cmd := tt.repo.CheckoutLFS()
|
2024-05-06 19:14:04 +00:00
|
|
|
assert.Equal(t, tt.want, cmd.Args)
|
2024-05-06 18:30:18 +00:00
|
|
|
})
|
2023-12-22 23:59:23 +00:00
|
|
|
}
|
|
|
|
}
|