...

Source file src/edge-infra.dev/pkg/k8s/testing/kmp/metadata.go

Documentation: edge-infra.dev/pkg/k8s/testing/kmp

     1  package kmp
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"gotest.tools/v3/assert/cmp"
     7  	"sigs.k8s.io/controller-runtime/pkg/client"
     8  
     9  	"edge-infra.dev/pkg/k8s/object"
    10  )
    11  
    12  // HasAnnotation checks that the compared object has an annotation with the
    13  // expected key and value.
    14  func HasAnnotation(key, value string) Komparison {
    15  	return func(o client.Object) cmp.Result {
    16  		if o.GetAnnotations()[key] == value {
    17  			return cmp.ResultSuccess
    18  		}
    19  		return cmp.ResultFailure(fmt.Sprintf(
    20  			"%s doesn't contain expected annotation '%s:%s'",
    21  			object.FmtObject(o), key, value),
    22  		)
    23  	}
    24  }
    25  

View as plain text