0
0
mirror of https://github.com/thegeeklab/wp-git-action.git synced 2024-11-09 17:10:41 +00:00
wp-git-action/git/commit_test.go

106 lines
2.1 KiB
Go
Raw Normal View History

package git
import (
"testing"
2024-05-06 19:04:48 +00:00
"github.com/stretchr/testify/assert"
)
func TestAdd(t *testing.T) {
tests := []struct {
name string
repo Repository
want []string
}{
{
name: "add all files",
repo: Repository{
WorkDir: "/path/to/repo",
},
want: []string{gitBin, "add", "--all"},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
2024-05-06 18:29:57 +00:00
cmd := tt.repo.Add()
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 TestIsCleanTree(t *testing.T) {
tests := []struct {
name string
repo Repository
want []string
}{
{
name: "clean working tree",
repo: Repository{
WorkDir: "/path/to/repo",
},
want: []string{gitBin, "diff-index", "--quiet", "HEAD", "--ignore-submodules"},
},
{
name: "unclean working tree",
repo: Repository{
WorkDir: "/path/to/unclean/repo",
},
want: []string{gitBin, "diff-index", "--quiet", "HEAD", "--ignore-submodules"},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
2024-05-06 18:29:57 +00:00
cmd := tt.repo.IsCleanTree()
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-06 18:29:57 +00:00
func TestCommit(t *testing.T) {
tests := []struct {
name string
repo Repository
want []string
}{
{
2024-05-06 18:29:57 +00:00
name: "commit with message",
repo: Repository{
WorkDir: "/path/to/repo",
2024-05-06 18:29:57 +00:00
CommitMsg: "Initial commit",
},
want: []string{gitBin, "commit", "-m", "Initial commit"},
},
{
name: "commit with empty commit",
repo: Repository{
WorkDir: "/path/to/repo",
CommitMsg: "Empty commit",
EmptyCommit: true,
},
2024-05-06 18:29:57 +00:00
want: []string{gitBin, "commit", "-m", "Empty commit", "--allow-empty"},
},
{
2024-05-06 18:29:57 +00:00
name: "commit with no verify",
repo: Repository{
WorkDir: "/path/to/repo",
2024-05-06 18:29:57 +00:00
CommitMsg: "No verify commit",
NoVerify: true,
},
2024-05-06 18:29:57 +00:00
want: []string{gitBin, "commit", "-m", "No verify commit", "--no-verify"},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
2024-05-06 18:29:57 +00:00
cmd := tt.repo.Commit()
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)
})
}
}