...

Source file src/github.com/linkerd/linkerd2/viz/tap/pkg/protohttp_test.go

Documentation: github.com/linkerd/linkerd2/viz/tap/pkg

     1  package pkg
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  
     7  	metricsPb "github.com/linkerd/linkerd2/viz/metrics-api/gen/viz"
     8  	tapPb "github.com/linkerd/linkerd2/viz/tap/gen/tap"
     9  )
    10  
    11  func TestTapReqToURL(t *testing.T) {
    12  	expectations := []struct {
    13  		req *tapPb.TapByResourceRequest
    14  		url string
    15  	}{
    16  		{
    17  			req: &tapPb.TapByResourceRequest{},
    18  			url: "/apis/tap.linkerd.io/v1alpha1/watch/namespaces//s//tap",
    19  		},
    20  		{
    21  			req: &tapPb.TapByResourceRequest{
    22  				Target: &metricsPb.ResourceSelection{
    23  					Resource: &metricsPb.Resource{
    24  						Type: "namespace",
    25  						Name: "test-name",
    26  					},
    27  				},
    28  			},
    29  			url: "/apis/tap.linkerd.io/v1alpha1/watch/namespaces/test-name/tap",
    30  		},
    31  		{
    32  			req: &tapPb.TapByResourceRequest{
    33  				Target: &metricsPb.ResourceSelection{
    34  					Resource: &metricsPb.Resource{
    35  						Namespace: "test-ns",
    36  						Type:      "test-type",
    37  						Name:      "test-name",
    38  					},
    39  				},
    40  			},
    41  			url: "/apis/tap.linkerd.io/v1alpha1/watch/namespaces/test-ns/test-types/test-name/tap",
    42  		},
    43  	}
    44  	for i, exp := range expectations {
    45  		exp := exp // pin
    46  
    47  		t.Run(fmt.Sprintf("%d constructs the expected URL from a TapRequest", i), func(t *testing.T) {
    48  			url := TapReqToURL(exp.req)
    49  			if url != exp.url {
    50  				t.Fatalf("Unexpected url: %s, Expected: %s", url, exp.url)
    51  			}
    52  		})
    53  	}
    54  }
    55  

View as plain text