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:
authorSami Hiltunen <shiltunen@gitlab.com>2021-08-03 17:51:47 +0300
committerSami Hiltunen <shiltunen@gitlab.com>2021-08-03 17:51:47 +0300
commitb0501701fea3ccd854d1c44129cd71e4dc8b9c6b (patch)
tree945f26520aa89fdaf97ce489535e5cda32bc0a05
parent00587e6348fbd209f9f53bfb34e7429b35fe5a0a (diff)
Remove unnecessary nil checksmh-port-find-license
FindLicense currently checks whether the repository sent in the message is nil or not and sends and empty response if so. This should be an error instead, so let's remove the check and return an error if necessary.
-rw-r--r--internal/gitaly/service/repository/license.go4
-rw-r--r--internal/gitaly/service/repository/license_test.go23
2 files changed, 20 insertions, 7 deletions
diff --git a/internal/gitaly/service/repository/license.go b/internal/gitaly/service/repository/license.go
index ee5f19d13..a3d2fb4f1 100644
--- a/internal/gitaly/service/repository/license.go
+++ b/internal/gitaly/service/repository/license.go
@@ -22,10 +22,6 @@ import (
func (s *server) FindLicense(ctx context.Context, req *gitalypb.FindLicenseRequest) (*gitalypb.FindLicenseResponse, error) {
if featureflag.GoFindLicense.IsEnabled(ctx) {
- if req.GetRepository() == nil {
- return &gitalypb.FindLicenseResponse{}, nil
- }
-
repo := localrepo.New(s.gitCmdFactory, s.catfileCache, req.GetRepository(), s.cfg)
hasHeadRevision, err := repo.HasRevision(ctx, "HEAD")
diff --git a/internal/gitaly/service/repository/license_test.go b/internal/gitaly/service/repository/license_test.go
index cd5612c98..5b50bcccc 100644
--- a/internal/gitaly/service/repository/license_test.go
+++ b/internal/gitaly/service/repository/license_test.go
@@ -21,11 +21,18 @@ func testSuccessfulFindLicenseRequest(t *testing.T, cfg config.Cfg, rubySrv *rub
featureflag.GoFindLicense,
}).Run(t, func(t *testing.T, ctx context.Context) {
for _, tc := range []struct {
- desc string
- files map[string]string
- expectedLicense string
+ desc string
+ nonExistentRepository bool
+ files map[string]string
+ expectedLicense string
+ errorContains string
}{
{
+ desc: "repository does not exist",
+ nonExistentRepository: true,
+ errorContains: "rpc error: code = NotFound desc = GetRepoPath: not a git repository",
+ },
+ {
desc: "empty if no license file in repo",
files: map[string]string{
"README.md": "readme content",
@@ -83,7 +90,17 @@ SOFTWARE.`},
gittest.WriteCommit(t, cfg, repoPath, gittest.WithBranch("master"), gittest.WithTreeEntries(treeEntries...), gittest.WithParents())
+ if tc.nonExistentRepository {
+ clean()
+ }
+
resp, err := client.FindLicense(ctx, &gitalypb.FindLicenseRequest{Repository: repo})
+ if tc.errorContains != "" {
+ require.Error(t, err)
+ require.Contains(t, err.Error(), tc.errorContains)
+ return
+ }
+
require.NoError(t, err)
testassert.ProtoEqual(t, &gitalypb.FindLicenseResponse{
LicenseShortName: tc.expectedLicense,