0
0
mirror of https://github.com/thegeeklab/wp-git-action.git synced 2024-11-22 00:00:39 +00:00
wp-git-action/git/clone_test.go

74 lines
1.4 KiB
Go
Raw Normal View History

package git
import (
"testing"
2024-05-06 19:04:48 +00:00
"github.com/stretchr/testify/assert"
)
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)
})
}
}
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)
})
}
}