Path: blob/main/components/common-go/baseserver/options_test.go
2498 views
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.1// Licensed under the GNU Affero General Public License (AGPL).2// See License.AGPL.txt in the project root for license information.34package baseserver56import (7"testing"8"time"910"github.com/gitpod-io/gitpod/common-go/log"11"github.com/heptiolabs/healthcheck"12"github.com/prometheus/client_golang/prometheus"13"github.com/stretchr/testify/require"14"google.golang.org/grpc/health/grpc_health_v1"15)1617func TestOptions(t *testing.T) {18logger := log.New()19timeout := 10 * time.Second20registry := prometheus.NewRegistry()21health := healthcheck.NewHandler()22grpcHealthService := &grpc_health_v1.UnimplementedHealthServer{}23httpCfg := ServerConfiguration{Address: "localhost:8080"}24grpcCfg := ServerConfiguration{Address: "localhost:8081"}2526var opts = []Option{27WithHTTP(&httpCfg),28WithGRPC(&grpcCfg),29WithLogger(logger),30WithCloseTimeout(timeout),31WithMetricsRegistry(registry),32WithHealthHandler(health),33WithGRPCHealthService(grpcHealthService),34WithVersion("foo-bar"),35}36actual, err := evaluateOptions(defaultOptions(), opts...)37require.NoError(t, err)3839expected := &options{40logger: logger,41config: &Configuration{42Services: ServicesConfiguration{43GRPC: &grpcCfg,44HTTP: &httpCfg,45},46},47closeTimeout: timeout,48metricsRegistry: registry,49healthHandler: health,50grpcHealthCheck: grpcHealthService,51version: "foo-bar",52}5354require.Equal(t, expected, actual)55}5657func TestLogger_ErrorsWithNilLogger(t *testing.T) {58_, err := evaluateOptions(defaultOptions(), WithLogger(nil))59require.Error(t, err)60}616263