-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathcryostat_conversion_test.go
157 lines (142 loc) · 7.59 KB
/
cryostat_conversion_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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
// Copyright The Cryostat Authors.
//
// 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 v1beta1_test
import (
operatorv1beta1 "github.com/cryostatio/cryostat-operator/api/v1beta1"
operatorv1beta2 "github.com/cryostatio/cryostat-operator/api/v1beta2"
"github.com/cryostatio/cryostat-operator/internal/controllers/model"
"github.com/cryostatio/cryostat-operator/internal/test"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
type conversionTestInput struct {
*test.TestResources
}
var _ = Describe("Cryostat", func() {
var t *conversionTestInput
BeforeEach(func() {
t = &conversionTestInput{
TestResources: &test.TestResources{
Name: "cryostat",
Namespace: "test",
TargetNamespaces: []string{"test"},
},
}
})
DescribeTable("converting from v1beta1 to v1beta2",
func(oldFunc func(*test.TestResources) *operatorv1beta1.Cryostat, newFunc func(*test.TestResources) *model.CryostatInstance) {
oldCR := oldFunc(t.TestResources)
newCRModel := newFunc(t.TestResources)
Expect(newCRModel.Object).To(BeAssignableToTypeOf(&operatorv1beta2.Cryostat{}))
newCR := newCRModel.Object.(*operatorv1beta2.Cryostat)
// Fill in Status.TargetNamespaces
newCR.Status.TargetNamespaces = newCR.Spec.TargetNamespaces
converted := &operatorv1beta2.Cryostat{}
err := oldCR.ConvertTo(converted)
Expect(err).ToNot(HaveOccurred())
Expect(converted).To(Equal(newCR))
},
tableEntriesTo(),
)
DescribeTable("converting from v1beta2 to v1beta1",
func(oldFunc func(*test.TestResources) *operatorv1beta1.Cryostat, newFunc func(*test.TestResources) *model.CryostatInstance) {
oldCR := oldFunc(t.TestResources)
newCRModel := newFunc(t.TestResources)
Expect(newCRModel.Object).To(BeAssignableToTypeOf(&operatorv1beta2.Cryostat{}))
newCR := newCRModel.Object.(*operatorv1beta2.Cryostat)
converted := &operatorv1beta1.Cryostat{}
err := converted.ConvertFrom(newCR)
Expect(err).ToNot(HaveOccurred())
Expect(converted).To(Equal(oldCR))
},
tableEntriesFrom(),
)
})
func tableEntriesTo() []TableEntry {
return append(tableEntries(), Entry("WS connections", (*test.TestResources).NewCryostatWithWsConnectionsSpecV1Beta1,
(*test.TestResources).NewCryostat))
}
func tableEntriesFrom() []TableEntry {
return tableEntries()
}
func tableEntries() []TableEntry {
return []TableEntry{
Entry("defaults", (*test.TestResources).NewCryostatV1Beta1,
(*test.TestResources).NewCryostat),
Entry("secrets", (*test.TestResources).NewCryostatWithSecretsV1Beta1,
(*test.TestResources).NewCryostatWithSecrets),
Entry("templates", (*test.TestResources).NewCryostatWithTemplatesV1Beta1,
(*test.TestResources).NewCryostatWithTemplates),
Entry("ingress", (*test.TestResources).NewCryostatWithIngressV1Beta1,
(*test.TestResources).NewCryostatWithIngress),
Entry("ingress with cert-manager disabled", (*test.TestResources).NewCryostatWithIngressCertManagerDisabledV1Beta1,
(*test.TestResources).NewCryostatWithIngressCertManagerDisabled),
Entry("PVC spec", (*test.TestResources).NewCryostatWithPVCSpecV1Beta1,
(*test.TestResources).NewCryostatWithPVCSpec),
Entry("PVC spec with some defaults", (*test.TestResources).NewCryostatWithPVCSpecSomeDefaultV1Beta1,
(*test.TestResources).NewCryostatWithPVCSpecSomeDefault),
Entry("PVC spec with labels only", (*test.TestResources).NewCryostatWithPVCLabelsOnlyV1Beta1,
(*test.TestResources).NewCryostatWithPVCLabelsOnly),
Entry("default emptyDir", (*test.TestResources).NewCryostatWithDefaultEmptyDirV1Beta1,
(*test.TestResources).NewCryostatWithDefaultEmptyDir),
Entry("custom emptyDir", (*test.TestResources).NewCryostatWithEmptyDirSpecV1Beta1,
(*test.TestResources).NewCryostatWithEmptyDirSpec),
Entry("core service", (*test.TestResources).NewCryostatWithCoreSvcV1Beta1,
(*test.TestResources).NewCryostatWithCoreSvc),
Entry("Grafana service", (*test.TestResources).NewCryostatWithGrafanaSvcV1Beta1,
(*test.TestResources).NewCryostatWithGrafanaSvc),
Entry("reports service", (*test.TestResources).NewCryostatWithReportsSvcV1Beta1,
(*test.TestResources).NewCryostatWithReportsSvc),
Entry("core ingress", (*test.TestResources).NewCryostatWithCoreNetworkOptionsV1Beta1,
(*test.TestResources).NewCryostatWithCoreNetworkOptions),
Entry("Grafana ingress", (*test.TestResources).NewCryostatWithGrafanaNetworkOptionsV1Beta1,
(*test.TestResources).NewCryostatWithGrafanaNetworkOptions),
Entry("reports resources", (*test.TestResources).NewCryostatWithReportsResourcesV1Beta1,
(*test.TestResources).NewCryostatWithReportsResources),
Entry("reports low resource limit", (*test.TestResources).NewCryostatWithReportLowResourceLimitV1Beta1,
(*test.TestResources).NewCryostatWithReportLowResourceLimit),
Entry("scheduling", (*test.TestResources).NewCryostatWithSchedulingV1Beta1,
(*test.TestResources).NewCryostatWithScheduling),
Entry("reports scheduling", (*test.TestResources).NewCryostatWithReportsSchedulingV1Beta1,
(*test.TestResources).NewCryostatWithReportsScheduling),
Entry("cert-manager disabled", (*test.TestResources).NewCryostatCertManagerDisabledV1Beta1,
(*test.TestResources).NewCryostatCertManagerDisabled),
Entry("cert-manager undefined", (*test.TestResources).NewCryostatCertManagerUndefinedV1Beta1,
(*test.TestResources).NewCryostatCertManagerUndefined),
Entry("resources", (*test.TestResources).NewCryostatWithResourcesV1Beta1,
(*test.TestResources).NewCryostatWithResources),
Entry("low resource limit", (*test.TestResources).NewCryostatWithLowResourceLimitV1Beta1,
(*test.TestResources).NewCryostatWithLowResourceLimit),
Entry("auth properties", (*test.TestResources).NewCryostatWithAuthPropertiesV1Beta1,
(*test.TestResources).NewCryostatWithAuthProperties),
Entry("built-in discovery disabled", (*test.TestResources).NewCryostatWithBuiltInDiscoveryDisabledV1Beta1,
(*test.TestResources).NewCryostatWithBuiltInDiscoveryDisabled),
Entry("discovery port custom config", (*test.TestResources).NewCryostatWithDiscoveryPortConfigV1Beta1,
(*test.TestResources).NewCryostatWithDiscoveryPortConfig),
Entry("discovery port config disabled", (*test.TestResources).NewCryostatWithBuiltInPortConfigDisabledV1Beta1,
(*test.TestResources).NewCryostatWithBuiltInPortConfigDisabled),
Entry("JMX cache options", (*test.TestResources).NewCryostatWithJmxCacheOptionsSpecV1Beta1,
(*test.TestResources).NewCryostatWithJmxCacheOptionsSpec),
Entry("subprocess heap", (*test.TestResources).NewCryostatWithReportSubprocessHeapSpecV1Beta1,
(*test.TestResources).NewCryostatWithReportSubprocessHeapSpec),
Entry("security", (*test.TestResources).NewCryostatWithSecurityOptionsV1Beta1,
(*test.TestResources).NewCryostatWithSecurityOptions),
Entry("reports security", (*test.TestResources).NewCryostatWithReportSecurityOptionsV1Beta1,
(*test.TestResources).NewCryostatWithReportSecurityOptions),
Entry("database secret", (*test.TestResources).NewCryostatWithDatabaseSecretProvidedV1Beta1,
(*test.TestResources).NewCryostatWithDatabaseSecretProvided),
Entry("metadata", (*test.TestResources).NewCryostatWithAdditionalMetadataV1Beta1,
(*test.TestResources).NewCryostatWithAdditionalMetadata),
}
}