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