diff options
author | Nick Thomas <nick@gitlab.com> | 2021-07-30 16:09:07 +0100 |
---|---|---|
committer | Nick Thomas <nick@gitlab.com> | 2021-07-30 17:11:15 +0100 |
commit | 72d70eab03d38b7c01054b7c598d17afe177212a (patch) | |
tree | f5a516a237c8856c46a569615ad63d2d37f3bb0d /internal/command/uploadarchive | |
parent | b7edd7dd9f957c6b14d3bfa4407aca9ddfbe4f52 (diff) | |
download | gitlab-shell-72d70eab03d38b7c01054b7c598d17afe177212a.tar.gz |
Remove some unreliable tests
Logrus buffers its output internally, which makes these tests fail
intermittently. They're also not a good example to follow generally.
We now have acceptance tests that exercise this functionality so I'm
pretty relaxed about losing the expectations. However, we can test
them by inspecting the server-received metadata too, so there's no loss
of coverage here.
The move from logrus to labkit for logging also makes these tests hard
to justify keeping.
Diffstat (limited to 'internal/command/uploadarchive')
-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") } |