diff options
author | Ash McKenzie <amckenzie@gitlab.com> | 2019-08-05 05:03:16 +0000 |
---|---|---|
committer | Ash McKenzie <amckenzie@gitlab.com> | 2019-08-05 05:03:16 +0000 |
commit | c577eb9ed8bd0336870f7a83302f70821d510169 (patch) | |
tree | ed7f7281633d97933e4465a2ac0f86d62c9a216e /go/internal/command/command_test.go | |
parent | ed0460374a5ca13d9ea17c6a9c21151319b7fd53 (diff) | |
parent | 3b6f9f7583755e041e76142d7caf7716937907fa (diff) | |
download | gitlab-shell-c577eb9ed8bd0336870f7a83302f70821d510169.tar.gz |
Merge branch '181-migrate-gitlab-shell-checks-fallback' into 'master'
Support falling back to ruby version of checkers
See merge request gitlab-org/gitlab-shell!318
Diffstat (limited to 'go/internal/command/command_test.go')
-rw-r--r-- | go/internal/command/command_test.go | 53 |
1 files changed, 38 insertions, 15 deletions
diff --git a/go/internal/command/command_test.go b/go/internal/command/command_test.go index 07260dd..ea88a6a 100644 --- a/go/internal/command/command_test.go +++ b/go/internal/command/command_test.go @@ -13,18 +13,22 @@ import ( "gitlab.com/gitlab-org/gitlab-shell/go/internal/command/uploadarchive" "gitlab.com/gitlab-org/gitlab-shell/go/internal/command/uploadpack" "gitlab.com/gitlab-org/gitlab-shell/go/internal/config" + "gitlab.com/gitlab-org/gitlab-shell/go/internal/executable" "gitlab.com/gitlab-org/gitlab-shell/go/internal/testhelper" ) func TestNew(t *testing.T) { testCases := []struct { desc string + executable *executable.Executable config *config.Config environment map[string]string + arguments []string expectedType interface{} }{ { - desc: "it returns a Discover command if the feature is enabled", + desc: "it returns a Discover command if the feature is enabled", + executable: &executable.Executable{Name: executable.GitlabShell}, config: &config.Config{ GitlabUrl: "http+unix://gitlab.socket", Migration: config.MigrationConfig{Enabled: true, Features: []string{"discover"}}, @@ -33,10 +37,12 @@ func TestNew(t *testing.T) { "SSH_CONNECTION": "1", "SSH_ORIGINAL_COMMAND": "", }, + arguments: []string{}, expectedType: &discover.Command{}, }, { - desc: "it returns a Fallback command no feature is enabled", + desc: "it returns a Fallback command no feature is enabled", + executable: &executable.Executable{Name: executable.GitlabShell}, config: &config.Config{ GitlabUrl: "http+unix://gitlab.socket", Migration: config.MigrationConfig{Enabled: false}, @@ -45,10 +51,12 @@ func TestNew(t *testing.T) { "SSH_CONNECTION": "1", "SSH_ORIGINAL_COMMAND": "", }, + arguments: []string{}, expectedType: &fallback.Command{}, }, { - desc: "it returns a TwoFactorRecover command if the feature is enabled", + desc: "it returns a TwoFactorRecover command if the feature is enabled", + executable: &executable.Executable{Name: executable.GitlabShell}, config: &config.Config{ GitlabUrl: "http+unix://gitlab.socket", Migration: config.MigrationConfig{Enabled: true, Features: []string{"2fa_recovery_codes"}}, @@ -57,10 +65,12 @@ func TestNew(t *testing.T) { "SSH_CONNECTION": "1", "SSH_ORIGINAL_COMMAND": "2fa_recovery_codes", }, + arguments: []string{}, expectedType: &twofactorrecover.Command{}, }, { - desc: "it returns an LfsAuthenticate command if the feature is enabled", + desc: "it returns an LfsAuthenticate command if the feature is enabled", + executable: &executable.Executable{Name: executable.GitlabShell}, config: &config.Config{ GitlabUrl: "http+unix://gitlab.socket", Migration: config.MigrationConfig{Enabled: true, Features: []string{"git-lfs-authenticate"}}, @@ -69,10 +79,12 @@ func TestNew(t *testing.T) { "SSH_CONNECTION": "1", "SSH_ORIGINAL_COMMAND": "git-lfs-authenticate", }, + arguments: []string{}, expectedType: &lfsauthenticate.Command{}, }, { - desc: "it returns a ReceivePack command if the feature is enabled", + desc: "it returns a ReceivePack command if the feature is enabled", + executable: &executable.Executable{Name: executable.GitlabShell}, config: &config.Config{ GitlabUrl: "http+unix://gitlab.socket", Migration: config.MigrationConfig{Enabled: true, Features: []string{"git-receive-pack"}}, @@ -81,10 +93,12 @@ func TestNew(t *testing.T) { "SSH_CONNECTION": "1", "SSH_ORIGINAL_COMMAND": "git-receive-pack", }, + arguments: []string{}, expectedType: &receivepack.Command{}, }, { - desc: "it returns a UploadPack command if the feature is enabled", + desc: "it returns an UploadPack command if the feature is enabled", + executable: &executable.Executable{Name: executable.GitlabShell}, config: &config.Config{ GitlabUrl: "http+unix://gitlab.socket", Migration: config.MigrationConfig{Enabled: true, Features: []string{"git-upload-pack"}}, @@ -93,10 +107,12 @@ func TestNew(t *testing.T) { "SSH_CONNECTION": "1", "SSH_ORIGINAL_COMMAND": "git-upload-pack", }, + arguments: []string{}, expectedType: &uploadpack.Command{}, }, { - desc: "it returns a UploadArchive command if the feature is enabled", + desc: "it returns an UploadArchive command if the feature is enabled", + executable: &executable.Executable{Name: executable.GitlabShell}, config: &config.Config{ GitlabUrl: "http+unix://gitlab.socket", Migration: config.MigrationConfig{Enabled: true, Features: []string{"git-upload-archive"}}, @@ -105,10 +121,12 @@ func TestNew(t *testing.T) { "SSH_CONNECTION": "1", "SSH_ORIGINAL_COMMAND": "git-upload-archive", }, + arguments: []string{}, expectedType: &uploadarchive.Command{}, }, { - desc: "it returns a Fallback command if the feature is unimplemented", + desc: "it returns a Fallback command if the feature is unimplemented", + executable: &executable.Executable{Name: executable.GitlabShell}, config: &config.Config{ GitlabUrl: "http+unix://gitlab.socket", Migration: config.MigrationConfig{Enabled: true, Features: []string{"git-unimplemented-feature"}}, @@ -117,6 +135,14 @@ func TestNew(t *testing.T) { "SSH_CONNECTION": "1", "SSH_ORIGINAL_COMMAND": "git-unimplemented-feature", }, + arguments: []string{}, + expectedType: &fallback.Command{}, + }, + { + desc: "it returns a Fallback command if executable is unknown", + executable: &executable.Executable{Name: "unknown"}, + config: &config.Config{}, + arguments: []string{}, expectedType: &fallback.Command{}, }, } @@ -126,7 +152,7 @@ func TestNew(t *testing.T) { restoreEnv := testhelper.TempEnv(tc.environment) defer restoreEnv() - command, err := New([]string{}, tc.config, nil) + command, err := New(tc.executable, tc.arguments, tc.config, nil) require.NoError(t, err) require.IsType(t, tc.expectedType, command) @@ -135,12 +161,9 @@ func TestNew(t *testing.T) { } func TestFailingNew(t *testing.T) { - t.Run("It returns an error when SSH_CONNECTION is not set", func(t *testing.T) { - restoreEnv := testhelper.TempEnv(map[string]string{}) - defer restoreEnv() - - _, err := New([]string{}, &config.Config{}, nil) + t.Run("It returns an error parsing arguments failed", func(t *testing.T) { + _, err := New(&executable.Executable{Name: executable.GitlabShell}, []string{}, &config.Config{}, nil) - require.Error(t, err, "Only ssh allowed") + require.Error(t, err) }) } |