0
0
mirror of https://github.com/thegeeklab/wp-git-action.git synced 2024-11-10 03:20:40 +00:00
wp-git-action/git/commit_test.go

106 lines
2.1 KiB
Go

package git
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestAdd(t *testing.T) {
tests := []struct {
name string
repo Repository
want []string
}{
{
name: "add all files",
repo: Repository{
WorkDir: "/path/to/repo",
Add: "",
},
want: []string{gitBin, "add", "--all"},
},
{
name: "add specific file",
repo: Repository{
WorkDir: "/path/to/repo",
Add: "file.go",
},
want: []string{gitBin, "add", "file.go"},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
cmd := Add(tt.repo)
require.Equal(t, tt.want, cmd.Cmd.Args)
require.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) {
cmd := IsCleanTree(tt.repo)
require.Equal(t, tt.want, cmd.Cmd.Args)
require.Equal(t, tt.repo.WorkDir, cmd.Cmd.Dir)
})
}
}
func TestEmptyCommit(t *testing.T) {
tests := []struct {
name string
repo Repository
want []string
}{
{
name: "empty commit with default options",
repo: Repository{
WorkDir: "/path/to/repo",
CommitMsg: "Empty commit",
},
want: []string{gitBin, "commit", "--allow-empty", "-m", "Empty commit"},
},
{
name: "empty commit with no-verify option",
repo: Repository{
WorkDir: "/path/to/repo",
CommitMsg: "Empty commit",
NoVerify: true,
},
want: []string{gitBin, "commit", "--allow-empty", "-m", "Empty commit", "--no-verify"},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
cmd := EmptyCommit(tt.repo)
require.Equal(t, tt.want, cmd.Cmd.Args)
require.Equal(t, tt.repo.WorkDir, cmd.Cmd.Dir)
})
}
}