...

Source file src/github.com/linkerd/linkerd2/pkg/profiles/test_helper.go

Documentation: github.com/linkerd/linkerd2/pkg/profiles

     1  package profiles
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/go-test/deep"
     7  	"github.com/linkerd/linkerd2/controller/gen/apis/serviceprofile/v1alpha2"
     8  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
     9  )
    10  
    11  // GenServiceProfile generates a mock ServiceProfile.
    12  func GenServiceProfile(service, namespace, clusterDomain string) v1alpha2.ServiceProfile {
    13  	return v1alpha2.ServiceProfile{
    14  		TypeMeta: ServiceProfileMeta,
    15  		ObjectMeta: metav1.ObjectMeta{
    16  			Name:      service + "." + namespace + ".svc." + clusterDomain,
    17  			Namespace: namespace,
    18  		},
    19  		Spec: v1alpha2.ServiceProfileSpec{
    20  			Routes: []*v1alpha2.RouteSpec{
    21  				{
    22  					Name: "/authors/{id}",
    23  					Condition: &v1alpha2.RequestMatch{
    24  						PathRegex: "/authors/\\d+",
    25  						Method:    "POST",
    26  					},
    27  					ResponseClasses: []*v1alpha2.ResponseClass{
    28  						{
    29  							Condition: &v1alpha2.ResponseMatch{
    30  								Status: &v1alpha2.Range{
    31  									Min: 500,
    32  									Max: 599,
    33  								},
    34  							},
    35  							IsFailure: true,
    36  						},
    37  					},
    38  				},
    39  			},
    40  		},
    41  	}
    42  }
    43  
    44  // ServiceProfileYamlEquals validates whether two ServiceProfiles are equal.
    45  func ServiceProfileYamlEquals(actual, expected v1alpha2.ServiceProfile) error {
    46  	if diff := deep.Equal(actual, expected); diff != nil {
    47  		return fmt.Errorf("ServiceProfile mismatch: %+v", diff)
    48  	}
    49  	return nil
    50  }
    51  

View as plain text