diff --git a/git/clone_test.go b/git/clone_test.go index 46ac00b..c0ef5ed 100644 --- a/git/clone_test.go +++ b/git/clone_test.go @@ -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) }) } } diff --git a/git/config_test.go b/git/config_test.go new file mode 100644 index 0000000..81e2949 --- /dev/null +++ b/git/config_test.go @@ -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) + }) + } +} diff --git a/git/init_test.go b/git/init_test.go new file mode 100644 index 0000000..fab4a94 --- /dev/null +++ b/git/init_test.go @@ -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) + }) + } +} diff --git a/git/remote_test.go b/git/remote_test.go new file mode 100644 index 0000000..05e5898 --- /dev/null +++ b/git/remote_test.go @@ -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) + }) + } +} diff --git a/git/submodule_test.go b/git/submodule_test.go index 56ab769..323f20c 100644 --- a/git/submodule_test.go +++ b/git/submodule_test.go @@ -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) }) } }