Skip to content
Snippets Groups Projects
Commit 27f22650 authored by Patrick Steinhardt's avatar Patrick Steinhardt
Browse files

ref: Refactor RefExists tests to generate data at runtime

Refactor RefExists tests to generate the test data at runtime, which
will enable us to start testing the RPC with the SHA256 object format.
While at it, convert the tests to be fully table-driven.
parent 430bfb49
No related merge requests found
//go:build !gitaly_test_sha256
package ref
import (
"testing"
"gitlab.com/gitlab-org/gitaly/v16/internal/git"
"gitlab.com/gitlab-org/gitaly/v16/internal/git/gittest"
"gitlab.com/gitlab-org/gitaly/v16/internal/gitaly/storage"
"gitlab.com/gitlab-org/gitaly/v16/internal/structerr"
"gitlab.com/gitlab-org/gitaly/v16/internal/testhelper"
"gitlab.com/gitlab-org/gitaly/v16/proto/go/gitalypb"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
func TestRefExists(t *testing.T) {
t.Parallel()
ctx := testhelper.Context(t)
_, repo, _, client := setupRefService(t, ctx)
cfg, client := setupRefServiceWithoutRepo(t)
repo, repoPath := gittest.CreateRepository(t, ctx, cfg)
commitID := gittest.WriteCommit(t, cfg, repoPath)
for _, ref := range []git.ReferenceName{"refs/heads/master", "refs/tags/v1.0.0", "refs/heads/'test'", "refs/heads/ʕ•ᴥ•ʔ"} {
gittest.WriteRef(t, cfg, repoPath, ref, commitID)
}
for _, tc := range []struct {
desc string
......@@ -25,6 +29,21 @@ func TestRefExists(t *testing.T) {
expectedResponse *gitalypb.RefExistsResponse
expectedErr error
}{
{
desc: "repository not provided",
request: &gitalypb.RefExistsRequest{
Repository: nil,
},
expectedErr: structerr.NewInvalidArgument("%w", storage.ErrRepositoryNotSet),
},
{
desc: "invalid ref name",
request: &gitalypb.RefExistsRequest{
Repository: repo,
Ref: []byte("in valid"),
},
expectedErr: structerr.NewInvalidArgument("invalid refname"),
},
{
desc: "master",
request: &gitalypb.RefExistsRequest{
......@@ -156,30 +175,3 @@ func TestRefExists(t *testing.T) {
})
}
}
func TestRefExists_validate(t *testing.T) {
t.Parallel()
ctx := testhelper.Context(t)
_, repo, _, client := setupRefService(t, ctx)
for _, tc := range []struct {
desc string
req *gitalypb.RefExistsRequest
expectedErr error
}{
{
desc: "repository not provided",
req: &gitalypb.RefExistsRequest{Repository: nil},
expectedErr: structerr.NewInvalidArgument("%w", storage.ErrRepositoryNotSet),
},
{
desc: "invalid ref name",
req: &gitalypb.RefExistsRequest{Repository: repo, Ref: []byte("in valid")},
expectedErr: status.Error(codes.InvalidArgument, "invalid refname"),
},
} {
t.Run(tc.desc, func(t *testing.T) {
_, err := client.RefExists(ctx, tc.req)
testhelper.RequireGrpcError(t, tc.expectedErr, err)
})
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment