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

59 lines
1.3 KiB
Go
Raw Normal View History

package plugin
import (
"testing"
2024-05-06 19:04:48 +00:00
"github.com/stretchr/testify/assert"
)
func TestSyncDirectories(t *testing.T) {
tests := []struct {
name string
exclude []string
del bool
debug bool
src string
dest string
want []string
}{
{
name: "exclude .git and other patterns",
exclude: []string{"*.log", "temp/"},
del: false,
debug: false,
src: "/path/to/src",
dest: "/path/to/dest",
want: []string{
"rsync", "-r", "--exclude", ".git", "--exclude", "*.log",
"--exclude", "temp/", ".", "/path/to/dest",
},
},
{
name: "delete enabled",
exclude: []string{},
del: true,
debug: false,
src: "/path/to/src",
dest: "/path/to/dest",
want: []string{"rsync", "-r", "--exclude", ".git", "--delete", ".", "/path/to/dest"},
},
{
name: "debug output enabled",
exclude: []string{},
del: false,
debug: true,
src: "/path/to/src",
dest: "/path/to/dest",
want: []string{"rsync", "-r", "--exclude", ".git", "--stats", ".", "/path/to/dest"},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
cmd := SyncDirectories(tt.exclude, tt.del, tt.src, tt.dest, tt.debug)
2024-05-06 19:04:48 +00:00
assert.Equal(t, tt.want, cmd.Cmd.Args)
assert.Equal(t, tt.src, cmd.Cmd.Dir)
})
}
}