From 3b6f9f7583755e041e76142d7caf7716937907fa Mon Sep 17 00:00:00 2001 From: Patrick Bajao Date: Fri, 2 Aug 2019 16:10:17 +0800 Subject: Add Executable struct This struct is responsible for determining the name and root dir of the executable. The `RootDir` property will be used to find the config. The `Name` property will be used to determine what `Command` and `CommandArgs` to be built. --- go/internal/command/command_test.go | 50 ++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 20 deletions(-) (limited to 'go/internal/command/command_test.go') diff --git a/go/internal/command/command_test.go b/go/internal/command/command_test.go index d8ef295..ea88a6a 100644 --- a/go/internal/command/command_test.go +++ b/go/internal/command/command_test.go @@ -5,7 +5,6 @@ import ( "github.com/stretchr/testify/require" - "gitlab.com/gitlab-org/gitlab-shell/go/internal/command/commandargs" "gitlab.com/gitlab-org/gitlab-shell/go/internal/command/discover" "gitlab.com/gitlab-org/gitlab-shell/go/internal/command/fallback" "gitlab.com/gitlab-org/gitlab-shell/go/internal/command/lfsauthenticate" @@ -14,19 +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"}}, @@ -35,11 +37,12 @@ func TestNew(t *testing.T) { "SSH_CONNECTION": "1", "SSH_ORIGINAL_COMMAND": "", }, - arguments: []string{string(commandargs.GitlabShell)}, + 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}, @@ -48,11 +51,12 @@ func TestNew(t *testing.T) { "SSH_CONNECTION": "1", "SSH_ORIGINAL_COMMAND": "", }, - arguments: []string{string(commandargs.GitlabShell)}, + 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"}}, @@ -61,11 +65,12 @@ func TestNew(t *testing.T) { "SSH_CONNECTION": "1", "SSH_ORIGINAL_COMMAND": "2fa_recovery_codes", }, - arguments: []string{string(commandargs.GitlabShell)}, + 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"}}, @@ -74,11 +79,12 @@ func TestNew(t *testing.T) { "SSH_CONNECTION": "1", "SSH_ORIGINAL_COMMAND": "git-lfs-authenticate", }, - arguments: []string{string(commandargs.GitlabShell)}, + 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"}}, @@ -87,11 +93,12 @@ func TestNew(t *testing.T) { "SSH_CONNECTION": "1", "SSH_ORIGINAL_COMMAND": "git-receive-pack", }, - arguments: []string{string(commandargs.GitlabShell)}, + 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"}}, @@ -100,11 +107,12 @@ func TestNew(t *testing.T) { "SSH_CONNECTION": "1", "SSH_ORIGINAL_COMMAND": "git-upload-pack", }, - arguments: []string{string(commandargs.GitlabShell)}, + 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"}}, @@ -113,11 +121,12 @@ func TestNew(t *testing.T) { "SSH_CONNECTION": "1", "SSH_ORIGINAL_COMMAND": "git-upload-archive", }, - arguments: []string{string(commandargs.GitlabShell)}, + 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"}}, @@ -126,13 +135,14 @@ func TestNew(t *testing.T) { "SSH_CONNECTION": "1", "SSH_ORIGINAL_COMMAND": "git-unimplemented-feature", }, - arguments: []string{string(commandargs.GitlabShell)}, + 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{"unknown"}, + arguments: []string{}, expectedType: &fallback.Command{}, }, } @@ -142,7 +152,7 @@ func TestNew(t *testing.T) { restoreEnv := testhelper.TempEnv(tc.environment) defer restoreEnv() - command, err := New(tc.arguments, tc.config, nil) + command, err := New(tc.executable, tc.arguments, tc.config, nil) require.NoError(t, err) require.IsType(t, tc.expectedType, command) @@ -152,7 +162,7 @@ func TestNew(t *testing.T) { func TestFailingNew(t *testing.T) { t.Run("It returns an error parsing arguments failed", func(t *testing.T) { - _, err := New([]string{}, &config.Config{}, nil) + _, err := New(&executable.Executable{Name: executable.GitlabShell}, []string{}, &config.Config{}, nil) require.Error(t, err) }) -- cgit v1.2.1