-
Notifications
You must be signed in to change notification settings - Fork 927
/
metadata.go
40 lines (32 loc) · 906 Bytes
/
metadata.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
package helpers
import (
"encoding/json"
. "github.com/onsi/gomega"
. "github.com/onsi/gomega/gexec"
)
type MetadataLabels map[string]string
func CheckExpectedLabels(url string, list bool, expected MetadataLabels) {
type commonResource struct {
Metadata struct {
Labels MetadataLabels
}
}
session := CF("curl", url)
Eventually(session).Should(Exit(0))
resourceJSON := session.Out.Contents()
var resource commonResource
if list {
var resourceList struct {
Resources []commonResource
}
Expect(json.Unmarshal(resourceJSON, &resourceList)).To(Succeed())
Expect(resourceList.Resources).To(HaveLen(1))
resource = resourceList.Resources[0]
} else {
Expect(json.Unmarshal(resourceJSON, &resource)).To(Succeed())
}
Expect(resource.Metadata.Labels).To(HaveLen(len(expected)))
for k, v := range expected {
Expect(resource.Metadata.Labels).To(HaveKeyWithValue(k, v))
}
}