mirror of
https://github.com/thegeeklab/wp-git-clone.git
synced 2024-11-24 23:10:40 +00:00
use assert instead of require
This commit is contained in:
parent
7fd0de6cc4
commit
2204435c15
@ -3,7 +3,7 @@ package git
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestFetchSource(t *testing.T) {
|
||||
@ -65,7 +65,7 @@ func TestFetchSource(t *testing.T) {
|
||||
for _, tt := range testdata {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
cmd := tt.repo.FetchSource(tt.repo.CommitRef)
|
||||
require.Equal(t, tt.want, cmd.Args)
|
||||
assert.Equal(t, tt.want, cmd.Args)
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -95,7 +95,7 @@ func TestFetchTags(t *testing.T) {
|
||||
for _, tt := range testdata {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
cmd := tt.repo.FetchTags()
|
||||
require.Equal(t, tt.want, cmd.Args)
|
||||
assert.Equal(t, tt.want, cmd.Args)
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -120,7 +120,7 @@ func TestFetchLFS(t *testing.T) {
|
||||
for _, tt := range testdata {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
cmd := tt.repo.FetchLFS()
|
||||
require.Equal(t, tt.want, cmd.Args)
|
||||
assert.Equal(t, tt.want, cmd.Args)
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -147,7 +147,7 @@ func TestCheckoutHead(t *testing.T) {
|
||||
for _, tt := range testdata {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
cmd := tt.repo.CheckoutHead()
|
||||
require.Equal(t, tt.want, cmd.Args)
|
||||
assert.Equal(t, tt.want, cmd.Args)
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -176,7 +176,7 @@ func TestCheckoutSha(t *testing.T) {
|
||||
for _, tt := range testdata {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
cmd := tt.repo.CheckoutSha()
|
||||
require.Equal(t, tt.want, cmd.Args)
|
||||
assert.Equal(t, tt.want, cmd.Args)
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -201,7 +201,7 @@ func TestCheckoutLFS(t *testing.T) {
|
||||
for _, tt := range testdata {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
cmd := tt.repo.CheckoutLFS()
|
||||
require.Equal(t, tt.want, cmd.Args)
|
||||
assert.Equal(t, tt.want, cmd.Args)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
121
git/config_test.go
Normal file
121
git/config_test.go
Normal file
@ -0,0 +1,121 @@
|
||||
package git
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestConfigSSLVerify(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
repo Repository
|
||||
skipVerify bool
|
||||
want []string
|
||||
}{
|
||||
{
|
||||
name: "enable SSL verification",
|
||||
repo: Repository{},
|
||||
skipVerify: false,
|
||||
want: []string{gitBin, "config", "--global", "http.sslVerify", "true"},
|
||||
},
|
||||
{
|
||||
name: "disable SSL verification",
|
||||
repo: Repository{},
|
||||
skipVerify: true,
|
||||
want: []string{gitBin, "config", "--global", "http.sslVerify", "false"},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
cmd := tt.repo.ConfigSSLVerify(tt.skipVerify)
|
||||
assert.Equal(t, tt.want, cmd.Cmd.Args)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigSafeDirectory(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
repo Repository
|
||||
safeDir string
|
||||
want []string
|
||||
}{
|
||||
{
|
||||
name: "set safe directory",
|
||||
repo: Repository{
|
||||
SafeDirectory: "/path/to/safe/dir",
|
||||
},
|
||||
want: []string{gitBin, "config", "--global", "--replace-all", "safe.directory", "/path/to/safe/dir"},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
cmd := tt.repo.ConfigSafeDirectory()
|
||||
assert.Equal(t, tt.want, cmd.Cmd.Args)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigRemapSubmodule(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
repo Repository
|
||||
subName string
|
||||
subURL string
|
||||
want []string
|
||||
}{
|
||||
{
|
||||
name: "remap submodule URL",
|
||||
repo: Repository{},
|
||||
subName: "mysubmodule",
|
||||
subURL: "https://example.com/mysubmodule.git",
|
||||
want: []string{
|
||||
gitBin, "config", "--global", "submodule.mysubmodule.url",
|
||||
"https://example.com/mysubmodule.git",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "remap submodule URL with spaces",
|
||||
repo: Repository{},
|
||||
subName: "my submodule",
|
||||
subURL: "https://example.com/my submodule.git",
|
||||
want: []string{
|
||||
gitBin, "config", "--global", "submodule.my submodule.url",
|
||||
"https://example.com/my submodule.git",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
cmd := tt.repo.ConfigRemapSubmodule(tt.subName, tt.subURL)
|
||||
assert.Equal(t, tt.want, cmd.Cmd.Args)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigSSHCommand(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
repo Repository
|
||||
sshKey string
|
||||
want []string
|
||||
}{
|
||||
{
|
||||
name: "set SSH command with key",
|
||||
repo: Repository{},
|
||||
sshKey: "/path/to/ssh/key",
|
||||
want: []string{gitBin, "config", "--global", "core.sshCommand", "ssh -i /path/to/ssh/key"},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
cmd := tt.repo.ConfigSSHCommand(tt.sshKey)
|
||||
assert.Equal(t, tt.want, cmd.Cmd.Args)
|
||||
})
|
||||
}
|
||||
}
|
30
git/init_test.go
Normal file
30
git/init_test.go
Normal file
@ -0,0 +1,30 @@
|
||||
package git
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestInit(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
repo Repository
|
||||
expected []string
|
||||
}{
|
||||
{
|
||||
name: "init repo",
|
||||
repo: Repository{
|
||||
Branch: "main",
|
||||
},
|
||||
expected: []string{gitBin, "init", "-b", "main"},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
cmd := tt.repo.Init()
|
||||
assert.Equal(t, tt.expected, cmd.Cmd.Args)
|
||||
})
|
||||
}
|
||||
}
|
31
git/remote_test.go
Normal file
31
git/remote_test.go
Normal file
@ -0,0 +1,31 @@
|
||||
package git
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestRemoteAdd(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
repo Repository
|
||||
want []string
|
||||
}{
|
||||
{
|
||||
name: "add remote with valid inputs",
|
||||
repo: Repository{
|
||||
RemoteURL: "https://example.com/repo.git",
|
||||
},
|
||||
want: []string{gitBin, "remote", "add", "origin", "https://example.com/repo.git"},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
cmd := tt.repo.RemoteAdd()
|
||||
assert.Equal(t, tt.want, cmd.Cmd.Args)
|
||||
assert.Equal(t, tt.repo.WorkDir, cmd.Cmd.Dir)
|
||||
})
|
||||
}
|
||||
}
|
@ -3,7 +3,7 @@ package git
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
// TestUpdateSubmodules tests if the arguments to `git submodule update`
|
||||
@ -78,7 +78,7 @@ func TestUpdateSubmodules(t *testing.T) {
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
cmd := tt.repo.SubmoduleUpdate()
|
||||
require.Equal(t, tt.want, cmd.Args)
|
||||
assert.Equal(t, tt.want, cmd.Args)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user