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