github.com/franc20/ayesa_sap@v7.0.0-beta.28.0.20200124003224-302d4d52fa6c+incompatible/integration/helpers/metadata.go (about)

     1  package helpers
     2  
     3  import (
     4  	"encoding/json"
     5  
     6  	. "github.com/onsi/gomega"
     7  	. "github.com/onsi/gomega/gexec"
     8  )
     9  
    10  type MetadataLabels map[string]string
    11  
    12  func CheckExpectedLabels(url string, list bool, expected MetadataLabels) {
    13  	type commonResource struct {
    14  		Metadata struct {
    15  			Labels MetadataLabels
    16  		}
    17  	}
    18  
    19  	session := CF("curl", url)
    20  	Eventually(session).Should(Exit(0))
    21  	resourceJSON := session.Out.Contents()
    22  	var resource commonResource
    23  
    24  	if list {
    25  		var resourceList struct {
    26  			Resources []commonResource
    27  		}
    28  
    29  		Expect(json.Unmarshal(resourceJSON, &resourceList)).To(Succeed())
    30  		Expect(resourceList.Resources).To(HaveLen(1))
    31  		resource = resourceList.Resources[0]
    32  	} else {
    33  		Expect(json.Unmarshal(resourceJSON, &resource)).To(Succeed())
    34  	}
    35  
    36  	Expect(resource.Metadata.Labels).To(HaveLen(len(expected)))
    37  	for k, v := range expected {
    38  		Expect(resource.Metadata.Labels).To(HaveKeyWithValue(k, v))
    39  	}
    40  }