0
0
mirror of https://github.com/thegeeklab/wp-git-clone.git synced 2024-11-22 10:20:38 +00:00
wp-git-clone/git/submodule_test.go

101 lines
1.7 KiB
Go
Raw Normal View History

2023-12-22 23:59:23 +00:00
package git
import (
"testing"
)
// TestUpdateSubmodules tests if the arguments to `git submodule update`
// are constructed properly.
func TestUpdateSubmodules(t *testing.T) {
tests := []struct {
partial bool
exp []string
}{
{
false,
[]string{
"/usr/bin/git",
"submodule",
"update",
"--init",
"--recursive",
},
},
{
true,
[]string{
"/usr/bin/git",
"submodule",
"update",
"--init",
"--recursive",
"--depth=1",
"--recommend-shallow",
},
},
}
for _, tt := range tests {
repo := Repository{
SubmoduleRemote: false,
SubmodulePartial: tt.partial,
}
c := SubmoduleUpdate(repo)
if len(c.Args) != len(tt.exp) {
t.Errorf("Expected: %s, got %s", tt.exp, c.Args)
}
for i := range c.Args {
if c.Args[i] != tt.exp[i] {
t.Errorf("Expected: %s, got %s", tt.exp, c.Args)
}
}
}
}
// TestUpdateSubmodules tests if the arguments to `git submodule update`
// are constructed properly.
func TestUpdateSubmodulesRemote(t *testing.T) {
tests := []struct {
exp []string
}{
{
[]string{
"/usr/bin/git",
"submodule",
"update",
"--init",
"--recursive",
"--remote",
},
},
{
[]string{
"/usr/bin/git",
"submodule",
"update",
"--init",
"--recursive",
"--remote",
},
},
}
for _, tt := range tests {
repo := Repository{
SubmoduleRemote: true,
SubmodulePartial: false,
}
c := SubmoduleUpdate(repo)
if len(c.Args) != len(tt.exp) {
t.Errorf("Expected: %s, got %s", tt.exp, c.Args)
}
for i := range c.Args {
if c.Args[i] != tt.exp[i] {
t.Errorf("Expected: %s, got %s", tt.exp, c.Args)
}
}
}
}