-
Notifications
You must be signed in to change notification settings - Fork 33
/
import_validation.go
125 lines (94 loc) · 5.01 KB
/
import_validation.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
// SPDX-FileCopyrightText: 2022 SAP SE or an SAP affiliate company and Gardener contributors.
//
// SPDX-License-Identifier: Apache-2.0
package importexport
import (
"context"
"path"
"path/filepath"
"time"
"github.com/gardener/landscaper/controller-utils/pkg/logging"
. "github.com/onsi/ginkgo/v2"
lsv1alpha1 "github.com/gardener/landscaper/apis/core/v1alpha1"
lsutils "github.com/gardener/landscaper/pkg/utils/landscaper"
"github.com/gardener/landscaper/test/framework"
"github.com/gardener/landscaper/test/utils"
)
func ImportValidationTests(f *framework.Framework) {
var (
testdataDir = filepath.Join(f.RootPath, "test", "integration", "testdata", "import-export")
)
Describe("Imports Validation", func() {
var (
state = f.Register()
ctx context.Context
)
log, err := logging.GetLogger()
if err != nil {
f.Log().Logfln("Error fetching logger: %w", err)
return
}
BeforeEach(func() {
ctx = context.Background()
ctx = logging.NewContext(ctx, log)
})
AfterEach(func() {
ctx.Done()
})
It("an installation should fail if a required import is missing", func() {
var (
doName = &lsv1alpha1.DataObject{} // contains the name of the ConfigMap to be deployed by the Installation
doNamespace = &lsv1alpha1.DataObject{} // contains the namespace of the ConfigMap
inst = &lsv1alpha1.Installation{}
)
By("Create import DataObject containing the ConfigMap namespace")
utils.ExpectNoError(utils.CreateNamespaceDataObjectFromFile(ctx, state.State, doNamespace, path.Join(testdataDir, "installation-5", "import-do-namespace.yaml")))
By("Create Target")
target, err := utils.BuildInternalKubernetesTarget(ctx, f.Client, state.Namespace, "my-cluster", f.RestConfig)
utils.ExpectNoError(err)
utils.ExpectNoError(state.Create(ctx, target))
By("Create Installation")
utils.ExpectNoError(utils.CreateInstallationFromFile(ctx, state.State, inst, path.Join(testdataDir, "installation-5", "installation-neg.yaml")))
By("Wait for installation to fail")
utils.ExpectNoError(lsutils.WaitForInstallationToFinish(ctx, f.Client, inst, lsv1alpha1.InstallationPhases.Failed, 2*time.Minute))
// Fix the installation by adding the missing import
By("Create import DataObject containing the ConfigMap name")
utils.ExpectNoError(utils.CreateDataObjectFromFile(ctx, state.State, doName, path.Join(testdataDir, "installation-5", "import-do-name.yaml")))
By("Update Installation")
utils.ExpectNoError(utils.UpdateInstallationFromFile(ctx, state.State, inst, path.Join(testdataDir, "installation-5", "installation-pos.yaml")))
By("Wait for Installation to succeed")
utils.ExpectNoError(lsutils.WaitForInstallationToFinish(ctx, f.Client, inst, lsv1alpha1.InstallationPhases.Succeeded, 2*time.Minute))
By("Check deployed ConfigMap")
expectedData := map[string]string{"foo": "bar"}
utils.ExpectNoError(utils.CheckConfigMap(ctx, state.State, "cm-example", expectedData))
})
It("an installation should fail if an import value has the wrong data type", func() {
var (
doName = &lsv1alpha1.DataObject{} // contains the name of the ConfigMap to be deployed by the Installation
doNamespace = &lsv1alpha1.DataObject{} // contains the namespace of the ConfigMap
inst = &lsv1alpha1.Installation{}
)
By("Create import DataObjects containing the ConfigMap name and namespace")
utils.ExpectNoError(utils.CreateDataObjectFromFile(ctx, state.State, doName, path.Join(testdataDir, "installation-6", "import-do-name-neg.yaml")))
utils.ExpectNoError(utils.CreateNamespaceDataObjectFromFile(ctx, state.State, doNamespace, path.Join(testdataDir, "installation-6", "import-do-namespace.yaml")))
By("Create Target")
target, err := utils.BuildInternalKubernetesTarget(ctx, f.Client, state.Namespace, "my-cluster", f.RestConfig)
utils.ExpectNoError(err)
utils.ExpectNoError(state.Create(ctx, target))
By("Create Installation")
utils.ExpectNoError(utils.CreateInstallationFromFile(ctx, state.State, inst, path.Join(testdataDir, "installation-6", "installation.yaml")))
By("Wait for installation to fail")
utils.ExpectNoError(lsutils.WaitForInstallationToFinish(ctx, f.Client, inst, lsv1alpha1.InstallationPhases.Failed, 2*time.Minute))
// Fix the type of import value
By("Update import DataObject containing the ConfigMap name")
utils.ExpectNoError(utils.UpdateDataObjectFromFile(ctx, state.State, doName, path.Join(testdataDir, "installation-6", "import-do-name-pos.yaml")))
By("Trigger a new reconciliation of the Installation")
utils.ExpectNoError(utils.UpdateInstallationFromFile(ctx, state.State, inst, path.Join(testdataDir, "installation-6", "installation.yaml")))
By("Wait for Installation to succeed")
utils.ExpectNoError(lsutils.WaitForInstallationToFinish(ctx, f.Client, inst, lsv1alpha1.InstallationPhases.Succeeded, 2*time.Minute))
By("Check deployed ConfigMap")
expectedData := map[string]string{"foo": "bar"}
utils.ExpectNoError(utils.CheckConfigMap(ctx, state.State, "cm-example", expectedData))
})
})
}