mirror of
https://github.com/thegeeklab/wp-git-action.git
synced 2024-11-09 17:10:41 +00:00
87 lines
1.5 KiB
Go
87 lines
1.5 KiB
Go
package git
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestStatus(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
repo Repository
|
|
want []string
|
|
}{
|
|
{
|
|
name: "with work dir",
|
|
repo: Repository{
|
|
WorkDir: "/path/to/repo",
|
|
},
|
|
want: []string{gitBin, "status", "--porcelain"},
|
|
},
|
|
{
|
|
name: "without work dir",
|
|
repo: Repository{},
|
|
want: []string{gitBin, "status", "--porcelain"},
|
|
},
|
|
{
|
|
name: "with custom stderr",
|
|
repo: Repository{
|
|
WorkDir: "/path/to/repo",
|
|
},
|
|
want: []string{gitBin, "status", "--porcelain"},
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
cmd := tt.repo.Status()
|
|
assert.Equal(t, tt.want, cmd.Cmd.Args)
|
|
assert.Equal(t, tt.repo.WorkDir, cmd.Cmd.Dir)
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestIsDirty(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
repo Repository
|
|
want bool
|
|
}{
|
|
{
|
|
name: "dirty repo",
|
|
repo: Repository{
|
|
WorkDir: t.TempDir(),
|
|
Branch: "main",
|
|
},
|
|
want: true,
|
|
},
|
|
{
|
|
name: "clean repo",
|
|
repo: Repository{
|
|
WorkDir: t.TempDir(),
|
|
Branch: "main",
|
|
},
|
|
want: false,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
if err := tt.repo.Init().Run(); err != nil {
|
|
assert.NoError(t, err)
|
|
}
|
|
|
|
if tt.want {
|
|
_, err := os.Create(filepath.Join(tt.repo.WorkDir, "dummy"))
|
|
assert.NoError(t, err)
|
|
}
|
|
|
|
isDirty := tt.repo.IsDirty()
|
|
assert.Equal(t, tt.want, isDirty)
|
|
})
|
|
}
|
|
}
|