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:
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>2020-12-17 18:44:32 +0300
committerÆvar Arnfjörð Bjarmason <avarab@gmail.com>2021-01-12 18:00:54 +0300
commitb999292653176613f76afbe66e829a2f3341b5a2 (patch)
treeb97a1ad15946443260a29a8449fa976cc686d4e5
parentea0e36b456646d87e88b3b966aeacdd48e71affe (diff)
UserCreateTag tests: use new update-ref mock to test update-ref erroravar/updater-fake-oldvalue-for-testing
This fixes a TODO item in be093ba33 (User{Branch,Tag,Submodule}: ferry update-ref errors upwards, 2020-12-14) for UserDeleteTag, we now know what response we return for update-ref failures. I'm also adding tests for the new UserCreateTag. This is a Go-only test, since in the Ruby codepath we're using libgit2. I don't think we're going to realistically have both Go & Ruby tests for features using this deep-gutsy fakery, but at least here we can see what we'd do in this scenario.
-rw-r--r--internal/gitaly/service/operations/tags_test.go78
1 files changed, 78 insertions, 0 deletions
diff --git a/internal/gitaly/service/operations/tags_test.go b/internal/gitaly/service/operations/tags_test.go
index 9202af691..fe9da56bf 100644
--- a/internal/gitaly/service/operations/tags_test.go
+++ b/internal/gitaly/service/operations/tags_test.go
@@ -9,7 +9,9 @@ import (
"testing"
"github.com/stretchr/testify/require"
+ "gitlab.com/gitlab-org/gitaly/internal/git"
"gitlab.com/gitlab-org/gitaly/internal/git/log"
+ "gitlab.com/gitlab-org/gitaly/internal/git/updateref"
"gitlab.com/gitlab-org/gitaly/internal/gitaly/config"
"gitlab.com/gitlab-org/gitaly/internal/helper/text"
"gitlab.com/gitlab-org/gitaly/internal/metadata/featureflag"
@@ -1253,6 +1255,82 @@ func testFailedUserCreateTagRequestDueToValidation(t *testing.T, ctx context.Con
}
}
+//nolint: errcheck
+func TestFailedUserDeleteTagRequestDueToUpdateRef(t *testing.T) {
+ ctx, cancel := testhelper.Context()
+ defer cancel()
+
+ ctx = featureflag.OutgoingCtxWithFeatureFlagValue(ctx, featureflag.GoUserDeleteTag, "true")
+
+ serverSocketPath, stop := runOperationServiceServer(t)
+ defer stop()
+
+ client, conn := newOperationClient(t, serverSocketPath)
+ defer conn.Close()
+
+ testRepo, testRepoPath, cleanupFn := testhelper.NewTestRepo(t)
+ defer cleanupFn()
+
+ tagName := "my-new-tag"
+ targetRevision := "c7fbe50c7c7419d9701eebe64b1fdacc3df5b9dd"
+ testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "tag", tagName, targetRevision)
+
+ tagID := testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "rev-parse", tagName)
+ require.Equal(t, targetRevision, text.ChompBytes(tagID))
+
+ updateref.MungeMapForTestingAdd(targetRevision, "612036fac47c5d31c212b17268e2f3ba807bce1e")
+ request := &gitalypb.UserDeleteTagRequest{
+ Repository: testRepo,
+ TagName: []byte(tagName),
+ User: testhelper.TestUser,
+ }
+ response, err := client.UserDeleteTag(ctx, request)
+ require.Equal(t, status.Errorf(codes.FailedPrecondition, "Could not update refs/tags/%s. Please refresh and try again.", tagName), err)
+ require.Nil(t, response)
+
+ tags := testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "for-each-ref", "--", "refs/tags/"+tagName)
+ require.Contains(t, string(tags), targetRevision)
+}
+
+//nolint: errcheck
+func TestFailedUserCreateTagRequestDueToUpdateRef(t *testing.T) {
+ ctx, cancel := testhelper.Context()
+ defer cancel()
+
+ ctx = featureflag.OutgoingCtxWithFeatureFlagValue(ctx, featureflag.GoUserCreateTag, "true")
+
+ serverSocketPath, stop := runOperationServiceServer(t)
+ defer stop()
+
+ client, conn := newOperationClient(t, serverSocketPath)
+ defer conn.Close()
+
+ testRepo, testRepoPath, cleanupFn := testhelper.NewTestRepo(t)
+ defer cleanupFn()
+
+ targetRevision := "c7fbe50c7c7419d9701eebe64b1fdacc3df5b9dd"
+ updateref.MungeMapForTestingAdd(git.NullSHA, "612036fac47c5d31c212b17268e2f3ba807bce1e")
+
+ tagName := "my-new-tag"
+ request := &gitalypb.UserCreateTagRequest{
+ Repository: testRepo,
+ TagName: []byte(tagName),
+ TargetRevision: []byte(targetRevision),
+ User: testhelper.TestUser,
+ }
+ response, err := client.UserCreateTag(ctx, request)
+ require.NoError(t, err)
+ require.Empty(t, response.PreReceiveError)
+ responseOk := &gitalypb.UserCreateTagResponse{
+ Tag: nil,
+ Exists: true,
+ }
+ require.Equal(t, responseOk, response)
+
+ tags := testhelper.MustRunCommand(t, nil, "git", "-C", testRepoPath, "for-each-ref", "--", "refs/tags/"+tagName)
+ require.Equal(t, string(tags), "")
+}
+
func TestTagHookOutput(t *testing.T) {
testhelper.NewFeatureSets([]featureflag.FeatureFlag{
featureflag.GoUserDeleteTag,