diff options
Diffstat (limited to 'internal/command/uploadarchive/gitalycall_test.go')
-rw-r--r-- | internal/command/uploadarchive/gitalycall_test.go | 47 |
1 files changed, 32 insertions, 15 deletions
diff --git a/internal/command/uploadarchive/gitalycall_test.go b/internal/command/uploadarchive/gitalycall_test.go index 3ec1449..302b949 100644 --- a/internal/command/uploadarchive/gitalycall_test.go +++ b/internal/command/uploadarchive/gitalycall_test.go @@ -5,7 +5,6 @@ import ( "context" "testing" - "github.com/sirupsen/logrus" "github.com/stretchr/testify/require" "gitlab.com/gitlab-org/labkit/correlation" @@ -13,12 +12,12 @@ import ( "gitlab.com/gitlab-org/gitlab-shell/internal/command/commandargs" "gitlab.com/gitlab-org/gitlab-shell/internal/command/readwriter" "gitlab.com/gitlab-org/gitlab-shell/internal/config" - "gitlab.com/gitlab-org/gitlab-shell/internal/testhelper" + "gitlab.com/gitlab-org/gitlab-shell/internal/sshenv" "gitlab.com/gitlab-org/gitlab-shell/internal/testhelper/requesthandlers" ) -func TestUploadPack(t *testing.T) { - gitalyAddress, _ := testserver.StartGitalyServer(t) +func TestUploadArchive(t *testing.T) { + gitalyAddress, testServer := testserver.StartGitalyServer(t) requests := requesthandlers.BuildAllowedWithGitalyHandlers(t, gitalyAddress) url := testserver.StartHttpServer(t, requests) @@ -29,13 +28,25 @@ func TestUploadPack(t *testing.T) { userId := "1" repo := "group/repo" + env := sshenv.Env{ + IsSSHConnection: true, + OriginalCommand: "git-upload-archive " + repo, + RemoteAddr: "127.0.0.1", + } + + args := &commandargs.Shell{ + GitlabKeyId: userId, + CommandType: commandargs.UploadArchive, + SshArgs: []string{"git-upload-archive", repo}, + Env: env, + } + cmd := &Command{ Config: &config.Config{GitlabUrl: url}, - Args: &commandargs.Shell{GitlabKeyId: userId, CommandType: commandargs.UploadArchive, SshArgs: []string{"git-upload-archive", repo}}, + Args: args, ReadWriter: &readwriter.ReadWriter{ErrOut: output, Out: output, In: input}, } - hook := testhelper.SetupLogger() ctx := correlation.ContextWithCorrelation(context.Background(), "a-correlation-id") ctx = correlation.ContextWithClientName(ctx, "gitlab-shell-tests") @@ -44,13 +55,19 @@ func TestUploadPack(t *testing.T) { require.Equal(t, "UploadArchive: "+repo, output.String()) - require.True(t, testhelper.WaitForLogEvent(hook)) - entries := hook.AllEntries() - require.Equal(t, 2, len(entries)) - require.Equal(t, logrus.InfoLevel, entries[1].Level) - require.Contains(t, entries[1].Message, "executing git command") - require.Contains(t, entries[1].Message, "command=git-upload-archive") - require.Contains(t, entries[1].Message, "gl_key_type=key") - require.Contains(t, entries[1].Message, "gl_key_id=123") - require.Contains(t, entries[1].Message, "correlation_id=a-correlation-id") + for k, v := range map[string]string{ + "gitaly-feature-cache_invalidator": "true", + "gitaly-feature-inforef_uploadpack_cache": "false", + "x-gitlab-client-name": "gitlab-shell-tests-git-upload-archive", + "key_id": "123", + "user_id": "1", + "remote_ip": "127.0.0.1", + "key_type": "key", + } { + actual := testServer.ReceivedMD[k] + require.Len(t, actual, 1) + require.Equal(t, v, actual[0]) + } + require.Empty(t, testServer.ReceivedMD["some-other-ff"]) + require.Equal(t, testServer.ReceivedMD["x-gitlab-correlation-id"][0], "a-correlation-id") } |