0
0
mirror of https://github.com/thegeeklab/wp-git-clone.git synced 2024-06-02 18:29:42 +02:00
wp-git-clone/git/submodule_test.go

85 lines
1.4 KiB
Go
Raw Normal View History

2023-12-23 00:59:23 +01:00
package git
import (
"testing"
2024-05-06 21:14:04 +02:00
"github.com/stretchr/testify/assert"
2023-12-23 00:59:23 +01:00
)
// TestUpdateSubmodules tests if the arguments to `git submodule update`
// are constructed properly.
func TestUpdateSubmodules(t *testing.T) {
tests := []struct {
name string
repo *Repository
want []string
2023-12-23 00:59:23 +01:00
}{
{
name: "full submodule update",
repo: &Repository{
SubmodulePartial: false,
},
want: []string{
gitBin,
2023-12-23 00:59:23 +01:00
"submodule",
"update",
"--init",
"--recursive",
},
},
{
name: "partial submodule update",
repo: &Repository{
SubmodulePartial: true,
},
want: []string{
gitBin,
2023-12-23 00:59:23 +01:00
"submodule",
"update",
"--init",
"--recursive",
"--depth=1",
"--recommend-shallow",
},
},
{
name: "submodule update with remote",
repo: &Repository{
SubmoduleRemote: true,
},
want: []string{
gitBin,
2023-12-23 00:59:23 +01:00
"submodule",
"update",
"--init",
"--recursive",
"--remote",
},
},
{
name: "submodule update with remote and partial",
repo: &Repository{
SubmoduleRemote: true,
SubmodulePartial: true,
},
want: []string{
gitBin,
2023-12-23 00:59:23 +01:00
"submodule",
"update",
"--init",
"--recursive",
"--depth=1",
"--recommend-shallow",
2023-12-23 00:59:23 +01:00
"--remote",
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
cmd := tt.repo.SubmoduleUpdate()
2024-05-06 21:14:04 +02:00
assert.Equal(t, tt.want, cmd.Args)
})
2023-12-23 00:59:23 +01:00
}
}