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/uploadpack/gitalycall_test.go | |
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/uploadpack/gitalycall_test.go')
-rw-r--r-- | internal/command/uploadpack/gitalycall_test.go | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/internal/command/uploadpack/gitalycall_test.go b/internal/command/uploadpack/gitalycall_test.go index 6b4c6ba..926d2c9 100644 --- a/internal/command/uploadpack/gitalycall_test.go +++ b/internal/command/uploadpack/gitalycall_test.go @@ -4,7 +4,6 @@ import ( "bytes" "context" "testing" - "time" "github.com/stretchr/testify/require" "gitlab.com/gitlab-org/labkit/correlation" @@ -13,7 +12,7 @@ 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" ) @@ -29,13 +28,25 @@ func TestUploadPack(t *testing.T) { userId := "1" repo := "group/repo" + env := sshenv.Env{ + IsSSHConnection: true, + OriginalCommand: "git-upload-pack " + repo, + RemoteAddr: "127.0.0.1", + } + + args := &commandargs.Shell{ + GitlabKeyId: userId, + CommandType: commandargs.UploadPack, + SshArgs: []string{"git-upload-pack", repo}, + Env: env, + } + cmd := &Command{ Config: &config.Config{GitlabUrl: url}, - Args: &commandargs.Shell{GitlabKeyId: userId, CommandType: commandargs.UploadPack, SshArgs: []string{"git-upload-pack", 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") @@ -43,25 +54,20 @@ func TestUploadPack(t *testing.T) { require.NoError(t, err) require.Equal(t, "UploadPack: "+repo, output.String()) - require.Eventually(t, func() bool { - entries := hook.AllEntries() - - require.Equal(t, 2, len(entries)) - require.Contains(t, entries[1].Message, "executing git command") - require.Contains(t, entries[1].Message, "command=git-upload-pack") - 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") - return true - }, time.Second, time.Millisecond) 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-pack", + "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") } |