2024-05-05 20:14:55 +00:00
|
|
|
package git
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2024-05-06 19:04:48 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
2024-05-05 20:14:55 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestFetchSource(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
repo Repository
|
|
|
|
want []string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "fetch from origin with branch",
|
|
|
|
repo: Repository{
|
|
|
|
WorkDir: "/path/to/repo",
|
|
|
|
Branch: "main",
|
|
|
|
},
|
|
|
|
want: []string{gitBin, "fetch", "origin", "+main:"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "fetch from origin with different branch",
|
|
|
|
repo: Repository{
|
|
|
|
WorkDir: "/path/to/repo",
|
|
|
|
Branch: "develop",
|
|
|
|
},
|
|
|
|
want: []string{gitBin, "fetch", "origin", "+develop:"},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
2024-05-06 18:29:57 +00:00
|
|
|
cmd := tt.repo.FetchSource()
|
2024-05-06 19:04:48 +00:00
|
|
|
assert.Equal(t, tt.want, cmd.Cmd.Args)
|
|
|
|
assert.Equal(t, tt.repo.WorkDir, cmd.Cmd.Dir)
|
2024-05-05 20:14:55 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestCheckoutHead(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
repo Repository
|
|
|
|
want []string
|
|
|
|
}{
|
|
|
|
{
|
|
|
|
name: "checkout head with branch",
|
|
|
|
repo: Repository{
|
|
|
|
WorkDir: "/path/to/repo",
|
|
|
|
Branch: "main",
|
|
|
|
},
|
|
|
|
want: []string{gitBin, "checkout", "-qf", "main"},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "checkout head with different branch",
|
|
|
|
repo: Repository{
|
|
|
|
WorkDir: "/path/to/repo",
|
|
|
|
Branch: "develop",
|
|
|
|
},
|
|
|
|
want: []string{gitBin, "checkout", "-qf", "develop"},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
2024-05-06 18:29:57 +00:00
|
|
|
cmd := tt.repo.CheckoutHead()
|
2024-05-06 19:04:48 +00:00
|
|
|
assert.Equal(t, tt.want, cmd.Cmd.Args)
|
|
|
|
assert.Equal(t, tt.repo.WorkDir, cmd.Cmd.Dir)
|
2024-05-05 20:14:55 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|