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

use assert instead of require

This commit is contained in:
Robert Kaussow 2024-05-06 21:14:04 +02:00
parent 7fd0de6cc4
commit 2204435c15
Signed by: xoxys
GPG Key ID: 4E692A2EAECC03C0
5 changed files with 191 additions and 9 deletions

View File

@ -3,7 +3,7 @@ package git
import ( import (
"testing" "testing"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/assert"
) )
func TestFetchSource(t *testing.T) { func TestFetchSource(t *testing.T) {
@ -65,7 +65,7 @@ func TestFetchSource(t *testing.T) {
for _, tt := range testdata { for _, tt := range testdata {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
cmd := tt.repo.FetchSource(tt.repo.CommitRef) 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 { for _, tt := range testdata {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
cmd := tt.repo.FetchTags() 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 { for _, tt := range testdata {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
cmd := tt.repo.FetchLFS() 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 { for _, tt := range testdata {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
cmd := tt.repo.CheckoutHead() 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 { for _, tt := range testdata {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
cmd := tt.repo.CheckoutSha() 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 { for _, tt := range testdata {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
cmd := tt.repo.CheckoutLFS() 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
View 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
View 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
View 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)
})
}
}

View File

@ -3,7 +3,7 @@ package git
import ( import (
"testing" "testing"
"github.com/stretchr/testify/require" "github.com/stretchr/testify/assert"
) )
// TestUpdateSubmodules tests if the arguments to `git submodule update` // TestUpdateSubmodules tests if the arguments to `git submodule update`
@ -78,7 +78,7 @@ func TestUpdateSubmodules(t *testing.T) {
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
cmd := tt.repo.SubmoduleUpdate() cmd := tt.repo.SubmoduleUpdate()
require.Equal(t, tt.want, cmd.Args) assert.Equal(t, tt.want, cmd.Args)
}) })
} }
} }