This repository was archived by the owner on Oct 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathchart_test.go
131 lines (116 loc) · 3.94 KB
/
chart_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// Copyright © 2023 Cisco Systems, Inc. and its affiliates.
// All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package helm
import (
"testing"
. "github.com/onsi/gomega"
envtypes "github.com/openclarity/vmclarity/testenv/types"
)
func TestChartWithContainerImages(t *testing.T) {
tests := []struct {
Name string
EnvVars map[string]string
HemConfig *Config
ContainerImagesMap map[string]string
ExpectedValues map[string]map[string]string
}{
{
Name: "Values with container images",
EnvVars: map[string]string{},
HemConfig: &Config{
Namespace: "default",
ReleaseName: "testenv-k8s-test",
ChartPath: "",
StorageDriver: "secret",
KubeConfigPath: "kubeconfig",
},
ContainerImagesMap: map[string]string{
"apiserver_image": "openclarity.io/vmclarity-apiserver",
"orchestrator_image": "openclarity.io/vmclarity-orchestrator:test@sha256:96374b22a50bcfc96b96b5153b185ce5bf16d7a454766747633a32d2f1fefead",
"ui_image": "ghcr.io/openclarity/vmclarity-ui:test",
"uibackend_image": "openclarity.io/vmclarity-uibackend:test",
"scanner_image": "vmclarity-scanner:test",
"cr_discovery_server_image": "openclarity.io/vmclarity-cr-discovery-server:test",
},
ExpectedValues: map[string]map[string]string{
"apiserver.image": {
"registry": "openclarity.io",
"repository": "vmclarity-apiserver",
"tag": "latest",
},
"orchestrator.image": {
"registry": "openclarity.io",
"repository": "vmclarity-orchestrator",
"tag": "test",
"digest": "sha256:96374b22a50bcfc96b96b5153b185ce5bf16d7a454766747633a32d2f1fefead",
},
"orchestrator.scannerImage": {
"registry": "docker.io",
"repository": "library/vmclarity-scanner",
"tag": "test",
},
"orchestrator.serviceAccount": {
"automountServiceAccountToken": "true",
},
"orchestrator": {
"provider": "kubernetes",
},
"ui.image": {
"registry": "ghcr.io",
"repository": "openclarity/vmclarity-ui",
"tag": "test",
},
"uibackend.image": {
"registry": "openclarity.io",
"repository": "vmclarity-uibackend",
"tag": "test",
},
"crDiscoveryServer.image": {
"registry": "openclarity.io",
"repository": "vmclarity-cr-discovery-server",
"tag": "test",
},
},
},
}
for _, test := range tests {
t.Run(test.Name, func(t *testing.T) {
g := NewGomegaWithT(t)
containerImages, err := envtypes.NewContainerImages[envtypes.ImageRef](test.ContainerImagesMap)
g.Expect(err).Should(Not(HaveOccurred()))
values := NewEmptyValues()
opts := []ValuesOpts{
WithContainerImages(containerImages),
WithKubernetesProvider(),
WithGatewayNodePort(30000),
}
err = applyValuesWithOpts(&values, opts...)
g.Expect(err).Should(Not(HaveOccurred()))
yaml, err := values.YAML()
g.Expect(err).Should(Not(HaveOccurred()))
t.Logf("values YAML: %v", yaml)
for subSection, expectedValues := range test.ExpectedValues {
t.Logf("with subsection: %s", subSection)
subValues, err := values.Table(subSection)
g.Expect(err).Should(Not(HaveOccurred()))
for key, expectedValue := range expectedValues {
actualValue, ok := subValues[key]
g.Expect(ok).Should(BeTrue())
g.Expect(actualValue).Should(BeEquivalentTo(expectedValue))
}
}
})
}
}