0
0
mirror of https://github.com/thegeeklab/wp-git-clone.git synced 2024-11-25 09:20:40 +00:00
wp-git-clone/git/submodule_test.go
2023-12-23 00:59:23 +01:00

101 lines
1.7 KiB
Go

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)
}
}
}
}