0
0
mirror of https://github.com/thegeeklab/wp-git-clone.git synced 2024-11-23 16:40:41 +00:00
wp-git-clone/git/clone_test.go

208 lines
3.2 KiB
Go
Raw Normal View History

2023-12-22 23:59:23 +00:00
package git
import (
"testing"
2024-05-06 19:14:04 +00:00
"github.com/stretchr/testify/assert"
2023-12-22 23:59:23 +00:00
)
func TestFetchSource(t *testing.T) {
2023-12-22 23:59:23 +00:00
testdata := []struct {
name string
repo *Repository
2023-12-22 23:59:23 +00:00
tags bool
depth int
want []string
2023-12-22 23:59:23 +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",
"+refs/heads/main:",
2023-12-22 23:59:23 +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",
"+refs/heads/main:",
2023-12-22 23:59:23 +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",
"+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)
})
}
}
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)
})
}
}
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)
})
}
}
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)
})
}
}
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)
})
}
}
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
},
},
}
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)
})
2023-12-22 23:59:23 +00:00
}
}