diff options
author | Sami Hiltunen <shiltunen@gitlab.com> | 2022-01-24 17:29:45 +0300 |
---|---|---|
committer | Sami Hiltunen <shiltunen@gitlab.com> | 2022-02-02 14:24:22 +0300 |
commit | c1e9a464611d66763e2e071042030e3c3a473f80 (patch) | |
tree | 80990cd1d7370fe8fa0780630d8859ff80a04c6e | |
parent | b9b42f5a824c664a6eddb551221904b6602488fd (diff) |
Allow passing in a ClientConn to CreateRepository
Some tests perform custom connection setup, for example when TLS is
used. To avoid complicating the general case of CreateRepository, this
commit adds an option to provide a pre-established ClientConn. This way
the test can perform whatever it needs to do to setup a connection and
CreateRepository doesn't need to get more complicated.
-rw-r--r-- | internal/git/gittest/repo.go | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/internal/git/gittest/repo.go b/internal/git/gittest/repo.go index 8734fff18..b250042c1 100644 --- a/internal/git/gittest/repo.go +++ b/internal/git/gittest/repo.go @@ -78,6 +78,9 @@ func newDiskHash(t testing.TB) string { // CreateRepositoryConfig allows for configuring how the repository is created. type CreateRepositoryConfig struct { + // ClientConn is the connection used to create the repository. If unset, the config is used to + // dial the service. + ClientConn *grpc.ClientConn // Storage determines the storage the repository is created in. If unset, the first storage // from the config is used. Storage config.Storage @@ -100,14 +103,20 @@ func CreateRepository(ctx context.Context, t testing.TB, cfg config.Cfg, configs opts = configs[0] } - dialOptions := []grpc.DialOption{} - if cfg.Auth.Token != "" { - dialOptions = append(dialOptions, grpc.WithPerRPCCredentials(gitalyauth.RPCCredentialsV2(cfg.Auth.Token))) + conn := opts.ClientConn + if conn == nil { + dialOptions := []grpc.DialOption{} + if cfg.Auth.Token != "" { + dialOptions = append(dialOptions, grpc.WithPerRPCCredentials(gitalyauth.RPCCredentialsV2(cfg.Auth.Token))) + } + + var err error + conn, err = client.DialContext(ctx, cfg.SocketPath, dialOptions) + require.NoError(t, err) + t.Cleanup(func() { conn.Close() }) } - conn, err := client.DialContext(ctx, cfg.SocketPath, dialOptions) - require.NoError(t, err) - t.Cleanup(func() { conn.Close() }) + client := gitalypb.NewRepositoryServiceClient(conn) storage := cfg.Storages[0] if (opts.Storage != config.Storage{}) { @@ -126,8 +135,6 @@ func CreateRepository(ctx context.Context, t testing.TB, cfg config.Cfg, configs GlProjectPath: GlProjectPath, } - client := gitalypb.NewRepositoryServiceClient(conn) - if opts.Seed != "" { _, err := client.CreateRepositoryFromURL(ctx, &gitalypb.CreateRepositoryFromURLRequest{ Repository: repository, |