-
Notifications
You must be signed in to change notification settings - Fork 33
/
import_executions.go
105 lines (90 loc) · 3.23 KB
/
import_executions.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
// 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"
. "github.com/onsi/gomega"
"gopkg.in/yaml.v3"
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 ImportExecutionsTests(f *framework.Framework) {
var (
testdataDir = filepath.Join(f.RootPath, "test", "integration", "testdata", "import-execution")
)
Describe("Import Executions", 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("should apply import executions", func() {
By("Create installation")
inst := &lsv1alpha1.Installation{}
utils.ExpectNoError(utils.ReadResourceFromFile(inst, path.Join(testdataDir, "installation-1", "installation.yaml")))
inst.SetNamespace(state.Namespace)
inst.Spec.ImportDataMappings = map[string]lsv1alpha1.AnyJSON{
"arbitraryImport": lsv1alpha1.NewAnyJSON([]byte(`"foo"`)),
"mapToList": lsv1alpha1.NewAnyJSON([]byte(`{
"foo": "bar",
"a": "b"
}`)),
}
utils.ExpectNoError(state.Create(ctx, inst))
utils.ExpectNoError(lsutils.WaitForInstallationToFinish(ctx, f.Client, inst, lsv1alpha1.InstallationPhases.Succeeded, 2*time.Minute))
By("Check deployitem")
dis, err := utils.GetDeployItemsOfInstallation(ctx, f.Client, inst)
utils.ExpectNoError(err)
Expect(dis).To(HaveLen(1))
di := dis[0]
config := map[string]interface{}{}
utils.ExpectNoError(yaml.Unmarshal(di.Spec.Configuration.Raw, &config))
Expect(config).To(HaveKey("imps"))
imports, ok := (config["imps"]).(map[string]interface{})
Expect(ok).To(BeTrue(), "imps could not be converted into map")
Expect(imports).To(HaveKeyWithValue("arbitraryImport", BeEquivalentTo("foo")))
Expect(imports).To(HaveKeyWithValue("mapToList", ConsistOf(
map[string]interface{}{
"key": "foo",
"value": "bar",
},
map[string]interface{}{
"key": "a",
"value": "b",
},
)))
})
It("should fail if import executions return errors", func() {
By("Create installation")
inst := &lsv1alpha1.Installation{}
utils.ExpectNoError(utils.ReadResourceFromFile(inst, path.Join(testdataDir, "installation-1", "installation.yaml")))
inst.SetNamespace(state.Namespace)
inst.Spec.ImportDataMappings = map[string]lsv1alpha1.AnyJSON{
"errors": lsv1alpha1.NewAnyJSON([]byte(`["a foo error occurred"]`)),
"arbitraryImport": lsv1alpha1.NewAnyJSON([]byte(`"foo"`)),
}
utils.ExpectNoError(state.Create(ctx, inst))
utils.ExpectNoError(lsutils.WaitForInstallationToFinish(ctx, f.Client, inst, lsv1alpha1.InstallationPhases.Failed, 2*time.Minute))
Expect(inst.Status.LastError.Message).To(ContainSubstring("a foo error occurred"))
})
})
}