Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitaly.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Steinhardt <psteinhardt@gitlab.com>2022-03-29 14:56:15 +0300
committerPatrick Steinhardt <psteinhardt@gitlab.com>2022-03-29 15:06:57 +0300
commite976d7cf390c5e6c9287036130a84074a112ac34 (patch)
treecfe83c81280548b919f6010837bb3eb6f148dbe2 /internal/gitaly/service
parent51da8bc17059e4ccd39873e4f3def935341472b8 (diff)
smarthttp: Refactor flaky test which checks that GitConfig is applied
One of our tests is verifying that the `GitConfigOptions` which can be passed to us via the `PostUploadPackRequest` is applied as expected. This is done by creating a reference and then injecting config which tells git-upload-pack(1) to hide this reference. If this config is applied as expected, then we should see that the server refuses to give us the object pointed to by the hidden reference. Refactor this test to be less reliant on the repository state, which is kind of confusing. The object pointed to by the hidden reference should in fact already be pointed to by another visible reference, which is quite puzzling. Furthermore, we also hard-code how many objects we expect to receive, which is one more thing that depends on this specific repository. Convert the test to use an empty repository instead and create two commits ad-hoc.
Diffstat (limited to 'internal/gitaly/service')
-rw-r--r--internal/gitaly/service/smarthttp/upload_pack_test.go34
1 files changed, 20 insertions, 14 deletions
diff --git a/internal/gitaly/service/smarthttp/upload_pack_test.go b/internal/gitaly/service/smarthttp/upload_pack_test.go
index 4b012eb31..a7b9e4c61 100644
--- a/internal/gitaly/service/smarthttp/upload_pack_test.go
+++ b/internal/gitaly/service/smarthttp/upload_pack_test.go
@@ -128,21 +128,27 @@ func testServerPostUploadPackGitConfigOptions(t *testing.T, ctx context.Context,
cfg.SocketPath = runSmartHTTPServer(t, cfg)
- repo, repoPath := gittest.CreateRepository(ctx, t, cfg, gittest.CreateRepositoryConfig{
- Seed: gittest.SeedGitLabTest,
- })
-
- want := "3dd08961455abf80ef9115f4afdc1c6f968b503c" // refs/heads/csv
- gittest.Exec(t, cfg, "-C", repoPath, "update-ref", "refs/hidden/csv", want)
- gittest.Exec(t, cfg, "-C", repoPath, "update-ref", "-d", "refs/heads/csv")
-
- have := "6ff234d2889b27d91c3442924ef6a100b1fc6f2b" // refs/heads/csv~1
+ repo, repoPath := gittest.CreateRepository(ctx, t, cfg)
+
+ // We write two commits: the first commit is a common base commit that is available via
+ // normal refs. And the second commit is a child of the base commit, but its reference is
+ // created as `refs/hidden/csv`. This allows us to hide this reference and thus verify that
+ // the gitconfig indeed is applied because we should not be able to fetch the hidden ref.
+ baseID := gittest.WriteCommit(t, cfg, repoPath,
+ gittest.WithMessage("base commit"),
+ gittest.WithParents(),
+ gittest.WithBranch("main"),
+ )
+ hiddenID := gittest.WriteCommit(t, cfg, repoPath,
+ gittest.WithMessage("hidden commit"),
+ gittest.WithParents(baseID),
+ )
+ gittest.Exec(t, cfg, "-C", repoPath, "update-ref", "refs/hidden/csv", hiddenID.String())
requestBody := &bytes.Buffer{}
-
- gittest.WritePktlineString(t, requestBody, fmt.Sprintf("want %s %s\n", want, clientCapabilities))
+ gittest.WritePktlineString(t, requestBody, fmt.Sprintf("want %s %s\n", hiddenID, clientCapabilities))
gittest.WritePktlineFlush(t, requestBody)
- gittest.WritePktlineString(t, requestBody, fmt.Sprintf("have %s\n", have))
+ gittest.WritePktlineString(t, requestBody, fmt.Sprintf("have %s\n", baseID))
gittest.WritePktlineFlush(t, requestBody)
t.Run("sanity check: ref exists and can be fetched", func(t *testing.T) {
@@ -151,7 +157,7 @@ func testServerPostUploadPackGitConfigOptions(t *testing.T, ctx context.Context,
response, err := makeRequest(ctx, t, cfg.SocketPath, cfg.Auth.Token, rpcRequest, bytes.NewReader(requestBody.Bytes()))
require.NoError(t, err)
_, _, count := extractPackDataFromResponse(t, response)
- require.Equal(t, 5, count, "pack should have 5 entries")
+ require.Equal(t, 1, count, "pack should have the hidden ID as single object")
})
t.Run("failing request because of hidden ref config", func(t *testing.T) {
@@ -167,7 +173,7 @@ func testServerPostUploadPackGitConfigOptions(t *testing.T, ctx context.Context,
// The failure message proves that upload-pack failed because of
// GitConfigOptions, and that proves that passing GitConfigOptions works.
- expected := fmt.Sprintf("0049ERR upload-pack: not our ref %v", want)
+ expected := fmt.Sprintf("0049ERR upload-pack: not our ref %v", hiddenID)
require.Equal(t, expected, response.String(), "Ref is hidden, expected error message did not appear")
})
}