|
| 1 | +// Copyright (c) 2022 Gitpod GmbH. All rights reserved. |
| 2 | +// Licensed under the MIT License. See License-MIT.txt in the project root for license information. |
| 3 | + |
| 4 | +package server |
| 5 | + |
| 6 | +import ( |
| 7 | + "testing" |
| 8 | + |
| 9 | + "github.com/gitpod-io/gitpod/installer/pkg/common" |
| 10 | + "github.com/gitpod-io/gitpod/installer/pkg/config/v1" |
| 11 | + "github.com/gitpod-io/gitpod/installer/pkg/config/v1/experimental" |
| 12 | + "github.com/gitpod-io/gitpod/installer/pkg/config/versions" |
| 13 | + "github.com/stretchr/testify/require" |
| 14 | + appsv1 "k8s.io/api/apps/v1" |
| 15 | + "k8s.io/utils/pointer" |
| 16 | +) |
| 17 | + |
| 18 | +func TestServerDeployment_MountsGithubAppSecret(t *testing.T) { |
| 19 | + ctx := renderContext(t) |
| 20 | + |
| 21 | + objects, err := deployment(ctx) |
| 22 | + require.NoError(t, err) |
| 23 | + |
| 24 | + require.Len(t, objects, 1, "must render only one object") |
| 25 | + |
| 26 | + deployment := objects[0].(*appsv1.Deployment) |
| 27 | + |
| 28 | + foundVol := false |
| 29 | + for _, vol := range deployment.Spec.Template.Spec.Volumes { |
| 30 | + if vol.Name == githubAppCertSecret { |
| 31 | + foundVol = true |
| 32 | + } |
| 33 | + } |
| 34 | + |
| 35 | + require.Truef(t, foundVol, "failed to find expected volume %q on server pod", githubAppCertSecret) |
| 36 | + |
| 37 | + serverContainer := deployment.Spec.Template.Spec.Containers[0] |
| 38 | + foundMount := false |
| 39 | + for _, vol := range serverContainer.VolumeMounts { |
| 40 | + if vol.Name == githubAppCertSecret { |
| 41 | + foundMount = true |
| 42 | + } |
| 43 | + } |
| 44 | + |
| 45 | + require.Truef(t, foundMount, "failed to find expected volume mount %q on server container", githubAppCertSecret) |
| 46 | +} |
| 47 | + |
| 48 | +func renderContext(t *testing.T) *common.RenderContext { |
| 49 | + ctx, err := common.NewRenderContext(config.Config{ |
| 50 | + Database: config.Database{ |
| 51 | + InCluster: pointer.Bool(true), |
| 52 | + }, |
| 53 | + Experimental: &experimental.Config{ |
| 54 | + WebApp: &experimental.WebAppConfig{ |
| 55 | + Server: &experimental.ServerConfig{ |
| 56 | + GithubApp: &experimental.GithubApp{ |
| 57 | + AppId: 0, |
| 58 | + AuthProviderId: "", |
| 59 | + BaseUrl: "", |
| 60 | + CertPath: "/some/cert/path", |
| 61 | + Enabled: false, |
| 62 | + LogLevel: "", |
| 63 | + MarketplaceName: "", |
| 64 | + WebhookSecret: "", |
| 65 | + CertSecretName: "some-secret-name", |
| 66 | + }, |
| 67 | + }, |
| 68 | + }, |
| 69 | + }, |
| 70 | + }, versions.Manifest{ |
| 71 | + Components: versions.Components{ |
| 72 | + ServiceWaiter: versions.Versioned{ |
| 73 | + Version: "arbitrary", |
| 74 | + }, |
| 75 | + Server: versions.Versioned{ |
| 76 | + Version: "arbitrary", |
| 77 | + }, |
| 78 | + }, |
| 79 | + }, "test-namespace") |
| 80 | + require.NoError(t, err) |
| 81 | + |
| 82 | + return ctx |
| 83 | +} |
0 commit comments