From 389ae3336772c9bbf7cd21f2f6aed262e8ae0357 Mon Sep 17 00:00:00 2001 From: Pavlo Strokov Date: Fri, 26 Jun 2020 11:16:27 +0000 Subject: Praefect: server factory introduction Introduces server factory for creating gRPC servers. Praefect gRPC server created by separate function and can be reused in tests to check routing. Part of: https://gitlab.com/gitlab-org/gitaly/-/issues/1698 --- internal/bootstrap/starter/starter.go | 7 ++++--- internal/bootstrap/starter/starter_test.go | 5 +++-- 2 files changed, 7 insertions(+), 5 deletions(-) (limited to 'internal/bootstrap') diff --git a/internal/bootstrap/starter/starter.go b/internal/bootstrap/starter/starter.go index 7c43781af..a8b7c018c 100644 --- a/internal/bootstrap/starter/starter.go +++ b/internal/bootstrap/starter/starter.go @@ -23,7 +23,8 @@ const ( ) var ( - errEmptySchema = errors.New("empty schema can't be used") + // ErrEmptySchema signals that the address has no schema in it. + ErrEmptySchema = errors.New("empty schema can't be used") errEmptyAddress = errors.New("empty address can't be used") ) @@ -36,7 +37,7 @@ func ParseEndpoint(endpoint string) (Config, error) { parts := strings.Split(endpoint, separator) if len(parts) != 2 { - return Config{}, fmt.Errorf("unsupported format: %q", endpoint) + return Config{}, fmt.Errorf("unsupported format: %q: %w", endpoint, ErrEmptySchema) } if err := verifySchema(parts[0]); err != nil { @@ -65,7 +66,7 @@ func ComposeEndpoint(schema, address string) (string, error) { func verifySchema(schema string) error { switch schema { case "": - return errEmptySchema + return ErrEmptySchema case TCP, TLS, Unix: return nil default: diff --git a/internal/bootstrap/starter/starter_test.go b/internal/bootstrap/starter/starter_test.go index 7347d0e13..c5d84b1f8 100644 --- a/internal/bootstrap/starter/starter_test.go +++ b/internal/bootstrap/starter/starter_test.go @@ -2,6 +2,7 @@ package starter import ( "errors" + "fmt" "testing" "github.com/stretchr/testify/require" @@ -110,12 +111,12 @@ func TestParseEndpoint(t *testing.T) { { desc: "no schema", addr: "://127.0.0.1:2306", - expErr: errEmptySchema, + expErr: ErrEmptySchema, }, { desc: "bad format", addr: "127.0.0.1:2306", - expErr: errors.New(`unsupported format: "127.0.0.1:2306"`), + expErr: fmt.Errorf(`unsupported format: "127.0.0.1:2306": %w`, ErrEmptySchema), }, { desc: "tcp schema addresses", -- cgit v1.2.3