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:
authorZeger-Jan van de Weg <git@zjvandeweg.nl>2020-11-26 17:32:27 +0300
committerZeger-Jan van de Weg <git@zjvandeweg.nl>2020-11-26 18:09:29 +0300
commited59266cf276b47e12b713b0003879050e06e3e7 (patch)
tree2b07a3ff052b746aa856ece56a4f5a68df7ecbdc
parent5defa2e52ce73df51d54d9088ff3e1e781e9d424 (diff)
testing: Deduplicate server and client setupzj-test-suite
Continuing the work of the parent commit, this change deduplicates the server and client setup. As such the tests have very little boilerplate left. The next item is probably the context.Context. Visually the code is less cluttered now, and less seems to be going on.
-rw-r--r--internal/gitaly/service/repository/info_attributes_test.go34
-rw-r--r--internal/gitaly/service/repository/suite_test.go19
-rw-r--r--internal/gitaly/service/repository/testhelper_test.go7
3 files changed, 36 insertions, 24 deletions
diff --git a/internal/gitaly/service/repository/info_attributes_test.go b/internal/gitaly/service/repository/info_attributes_test.go
index 3a682c9c1..984906469 100644
--- a/internal/gitaly/service/repository/info_attributes_test.go
+++ b/internal/gitaly/service/repository/info_attributes_test.go
@@ -6,20 +6,13 @@ import (
"os"
"path/filepath"
- "github.com/stretchr/testify/require"
- "gitlab.com/gitlab-org/gitaly/internal/gitaly/config"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
"gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
"gitlab.com/gitlab-org/gitaly/streamio"
)
func (suite *RepositoryServiceTestSuite) TestGetInfoAttributesExisting() {
- locator := config.NewLocator(config.Config)
- serverSocketPath, stop := runRepoServer(suite.T(), locator)
- defer stop()
-
- client, conn := newRepositoryClient(suite.T(), serverSocketPath)
- defer conn.Close()
+ require := suite.Require()
infoPath := filepath.Join(suite.repositoryPath, "info")
os.MkdirAll(infoPath, 0755)
@@ -28,41 +21,36 @@ func (suite *RepositoryServiceTestSuite) TestGetInfoAttributesExisting() {
data := bytes.Repeat([]byte("*.pbxproj binary\n"), buffSize)
attrsPath := filepath.Join(infoPath, "attributes")
err := ioutil.WriteFile(attrsPath, data, 0644)
- require.NoError(suite.T(), err)
+ require.NoError(err)
request := &gitalypb.GetInfoAttributesRequest{Repository: suite.repository}
testCtx, cancelCtx := testhelper.Context()
defer cancelCtx()
- stream, err := client.GetInfoAttributes(testCtx, request)
- require.NoError(suite.T(), err)
+ stream, err := suite.client.GetInfoAttributes(testCtx, request)
+ require.NoError(err)
receivedData, err := ioutil.ReadAll(streamio.NewReader(func() ([]byte, error) {
response, err := stream.Recv()
return response.GetAttributes(), err
}))
- require.NoError(suite.T(), err)
- require.Equal(suite.T(), data, receivedData)
+ require.NoError(err)
+ require.Equal(data, receivedData)
}
func (suite *RepositoryServiceTestSuite) TestGetInfoAttributesNonExisting() {
- locator := config.NewLocator(config.Config)
- serverSocketPath, stop := runRepoServer(suite.T(), locator)
- defer stop()
-
- client, conn := newRepositoryClient(suite.T(), serverSocketPath)
- defer conn.Close()
+ require := suite.Require()
request := &gitalypb.GetInfoAttributesRequest{Repository: suite.repository}
testCtx, cancelCtx := testhelper.Context()
defer cancelCtx()
- response, err := client.GetInfoAttributes(testCtx, request)
- require.NoError(suite.T(), err)
+ response, err := suite.client.GetInfoAttributes(testCtx, request)
+ require.NoError(err)
message, err := response.Recv()
- require.NoError(suite.T(), err)
+ require.NoError(err)
- require.Empty(suite.T(), message.GetAttributes())
+ require.Empty(message.GetAttributes())
}
diff --git a/internal/gitaly/service/repository/suite_test.go b/internal/gitaly/service/repository/suite_test.go
index 3954b0d19..0805b9d8f 100644
--- a/internal/gitaly/service/repository/suite_test.go
+++ b/internal/gitaly/service/repository/suite_test.go
@@ -4,8 +4,10 @@ import (
"testing"
"github.com/stretchr/testify/suite"
+ "gitlab.com/gitlab-org/gitaly/internal/gitaly/config"
"gitlab.com/gitlab-org/gitaly/internal/testhelper"
"gitlab.com/gitlab-org/gitaly/proto/go/gitalypb"
+ "google.golang.org/grpc"
)
type RepositoryServiceTestSuite struct {
@@ -15,6 +17,11 @@ type RepositoryServiceTestSuite struct {
repository *gitalypb.Repository
repositoryPath string
repoCleanupFn func()
+
+ srv *testhelper.TestServer
+
+ client gitalypb.RepositoryServiceClient
+ conn *grpc.ClientConn
}
// Setup the repository service server and testing repository
@@ -25,9 +32,21 @@ func (suite *RepositoryServiceTestSuite) SetupTest() {
suite.repository = testRepo
suite.repositoryPath = repoPath
suite.repoCleanupFn = cleanupFn
+
+ suite.srv = buildTestingServer(suite.T(), config.Config, config.NewLocator(config.Config))
+
+ req := suite.Require()
+ req.NoError(suite.srv.Start())
+
+ cl, conn := newRepositoryClient(suite.T(), "unix://"+suite.srv.Socket())
+ suite.client = cl
+ suite.conn = conn
}
func (suite *RepositoryServiceTestSuite) TearDownTest() {
+ suite.conn.Close()
+ suite.srv.Stop()
+
suite.repoCleanupFn()
}
diff --git a/internal/gitaly/service/repository/testhelper_test.go b/internal/gitaly/service/repository/testhelper_test.go
index 9095225ff..6b91fe479 100644
--- a/internal/gitaly/service/repository/testhelper_test.go
+++ b/internal/gitaly/service/repository/testhelper_test.go
@@ -96,7 +96,7 @@ func newSecureRepoClient(t *testing.T, serverSocketPath string, pool *x509.CertP
var NewSecureRepoClient = newSecureRepoClient
-func runRepoServerWithConfig(t *testing.T, cfg config.Cfg, locator storage.Locator, opts ...testhelper.TestServerOpt) (string, func()) {
+func buildTestingServer(t *testing.T, cfg config.Cfg, locator storage.Locator, opts ...testhelper.TestServerOpt) *testhelper.TestServer {
streamInt := []grpc.StreamServerInterceptor{
mcache.StreamInvalidator(dcache.LeaseKeyer{}, protoregistry.GitalyProtoPreregistered),
}
@@ -109,6 +109,11 @@ func runRepoServerWithConfig(t *testing.T, cfg config.Cfg, locator storage.Locat
gitalypb.RegisterRepositoryServiceServer(srv.GrpcServer(), NewServer(cfg, RubyServer, locator, config.Config.GitalyInternalSocketPath()))
reflection.Register(srv.GrpcServer())
+ return srv
+}
+
+func runRepoServerWithConfig(t *testing.T, cfg config.Cfg, locator storage.Locator, opts ...testhelper.TestServerOpt) (string, func()) {
+ srv := buildTestingServer(t, cfg, locator, opts...)
require.NoError(t, srv.Start())
return "unix://" + srv.Socket(), srv.Stop