-
Notifications
You must be signed in to change notification settings - Fork 233
/
Copy pathmanifest_test.go
105 lines (84 loc) · 2.85 KB
/
manifest_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
package mtv
import (
"strings"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/openshift/assisted-service/internal/common"
"github.com/openshift/assisted-service/models"
"sigs.k8s.io/yaml"
)
var _ = Describe("MTV manifest generation", func() {
operator := NewMTVOperator(common.GetTestLog())
var cluster *common.Cluster
getCluster := func(openshiftVersion string) *common.Cluster {
cluster := common.Cluster{Cluster: models.Cluster{
OpenshiftVersion: openshiftVersion,
}}
return &cluster
}
Context("MVP manifest", func() {
It("Check YAMLs of MTV", func() {
cluster = getCluster("4.16.0")
openshiftManifests, manifest, err := operator.GenerateManifests(cluster)
Expect(err).ShouldNot(HaveOccurred())
Expect(openshiftManifests).To(HaveLen(3))
Expect(openshiftManifests["50_openshift-mtv_ns.yaml"]).NotTo(HaveLen(0))
Expect(openshiftManifests["50_openshift-mtv_subscription.yaml"]).NotTo(HaveLen(0))
Expect(openshiftManifests["50_openshift-mtv_operator_group.yaml"]).NotTo(HaveLen(0))
for _, manifest := range openshiftManifests {
_, err = yaml.YAMLToJSON(manifest)
Expect(err).ShouldNot(HaveOccurred())
}
_, err = yaml.YAMLToJSON(manifest)
Expect(err).ShouldNot(HaveOccurred(), "yamltojson err: %v", err)
})
It("Check Subscription manifest", func() {
subscriptionData, err := getSubscription(Namespace, Subscription, Source, SourceName)
Expect(err).To(BeNil())
Expect(extractData(subscriptionData, "metadata.name")).To(Equal(Subscription))
Expect(extractData(subscriptionData, "metadata.namespace")).To(Equal(Namespace))
Expect(extractData(subscriptionData, "spec.source")).To(Equal(Source))
Expect(extractData(subscriptionData, "spec.name")).To(Equal(SourceName))
})
It("Check namespace manifest", func() {
nsData, err := getNamespace(Namespace)
Expect(err).To(BeNil())
Expect(extractData(nsData, "metadata.name")).To(Equal(Namespace))
})
It("Check operator group manifest", func() {
opData, err := getOperatorGroup(Namespace)
Expect(err).To(BeNil())
Expect(extractData(opData, "metadata.namespace")).To(Equal(Namespace))
})
It("Check controller manifest", func() {
controllerData, err := getController(Namespace)
Expect(err).To(BeNil())
Expect(extractData(controllerData, "metadata.namespace")).To(Equal(Namespace))
})
})
})
func extractData(manifest []byte, path string) string {
keys := strings.Split(path, ".")
var data interface{}
err := yaml.Unmarshal(manifest, &data)
Expect(err).ShouldNot(HaveOccurred())
ns := data.(map[string]interface{})
i := 0
for {
// don't look at the last key which should be a string
if i > len(keys)-2 {
break
}
subpath, ok := ns[keys[i]]
if !ok {
return ""
}
newData, ok := subpath.(map[string]interface{})
if !ok {
return ""
}
ns = newData
i++
}
return ns[keys[i]].(string)
}