Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/install/installer/pkg/components/public-api-server/configmap_test.go
2501 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 public_api_server
6
7
import (
8
"fmt"
9
"testing"
10
"time"
11
12
"github.com/gitpod-io/gitpod/installer/pkg/components/redis"
13
"github.com/gitpod-io/gitpod/installer/pkg/config/v1/experimental"
14
"github.com/google/go-cmp/cmp"
15
16
"github.com/gitpod-io/gitpod/common-go/baseserver"
17
"github.com/gitpod-io/gitpod/components/public-api/go/config"
18
"github.com/gitpod-io/gitpod/installer/pkg/common"
19
"github.com/stretchr/testify/require"
20
corev1 "k8s.io/api/core/v1"
21
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
22
)
23
24
func TestConfigMap(t *testing.T) {
25
ctx := renderContextWithPublicAPI(t)
26
objs, err := configmap(ctx)
27
require.NoError(t, err)
28
29
require.Len(t, objs, 1, "must only render one configmap")
30
31
var stripeSecretPath string
32
_ = ctx.WithExperimental(func(ucfg *experimental.Config) error {
33
_, _, stripeSecretPath, _ = getStripeConfig(ucfg)
34
return nil
35
})
36
37
var personalAccessTokenSigningKeyPath string
38
_ = ctx.WithExperimental(func(ucfg *experimental.Config) error {
39
_, _, personalAccessTokenSigningKeyPath, _ = getPersonalAccessTokenSigningKey(ucfg)
40
return nil
41
})
42
43
expectedConfiguration := config.Configuration{
44
PublicURL: fmt.Sprintf("https://services.%s", ctx.Config.Domain),
45
GitpodServiceURL: fmt.Sprintf("ws://server.%s.svc.cluster.local:3000", ctx.Namespace),
46
BillingServiceAddress: fmt.Sprintf("usage.%s.svc.cluster.local:9001", ctx.Namespace),
47
SessionServiceAddress: fmt.Sprintf("server.%s.svc.cluster.local:9876", ctx.Namespace),
48
StripeWebhookSigningSecretPath: stripeSecretPath,
49
PersonalAccessTokenSigningKeyPath: personalAccessTokenSigningKeyPath,
50
DatabaseConfigPath: "/secrets/database-config",
51
Redis: config.RedisConfiguration{
52
Address: fmt.Sprintf("%s.%s.svc.cluster.local:%d", redis.Component, ctx.Namespace, redis.Port),
53
},
54
Auth: config.AuthConfiguration{
55
PKI: config.AuthPKIConfiguration{
56
Signing: config.KeyPair{
57
ID: "0001",
58
PublicKeyPath: "/secrets/auth-pki/signing/tls.crt",
59
PrivateKeyPath: "/secrets/auth-pki/signing/tls.key",
60
},
61
},
62
Session: config.SessionConfig{
63
LifetimeSeconds: int64((24 * 7 * time.Hour).Seconds()),
64
Issuer: "https://test.domain.everything.awesome.is",
65
Cookie: config.CookieConfig{
66
Name: "__Host-_test_domain_everything_awesome_is_jwt2_",
67
MaxAge: int64((24 * 7 * time.Hour).Seconds()),
68
SameSite: "lax",
69
Secure: true,
70
HTTPOnly: true,
71
},
72
},
73
},
74
Server: &baseserver.Configuration{
75
Services: baseserver.ServicesConfiguration{
76
GRPC: &baseserver.ServerConfiguration{
77
Address: fmt.Sprintf("0.0.0.0:%d", GRPCContainerPort),
78
},
79
HTTP: &baseserver.ServerConfiguration{
80
Address: fmt.Sprintf("0.0.0.0:%d", HTTPContainerPort),
81
},
82
},
83
},
84
}
85
86
expectedJSON, err := common.ToJSONString(expectedConfiguration)
87
require.NoError(t, err)
88
89
cm := objs[0].(*corev1.ConfigMap)
90
91
expectation := &corev1.ConfigMap{
92
TypeMeta: common.TypeMetaConfigmap,
93
ObjectMeta: metav1.ObjectMeta{
94
Name: Component,
95
Namespace: ctx.Namespace,
96
Labels: common.CustomizeLabel(ctx, Component, common.TypeMetaConfigmap),
97
Annotations: common.CustomizeAnnotation(ctx, Component, common.TypeMetaConfigmap),
98
},
99
Data: map[string]string{
100
"config.json": string(expectedJSON),
101
},
102
}
103
if diff := cmp.Diff(expectation, cm); diff != "" {
104
t.Errorf("configMap mismatch (-want +got):\n%s", diff)
105
}
106
}
107
108