...

Source file src/github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/httprule/types_test.go

Documentation: github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/httprule

     1  package httprule
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  )
     7  
     8  func TestTemplateStringer(t *testing.T) {
     9  	for _, spec := range []struct {
    10  		segs []segment
    11  		want string
    12  	}{
    13  		{
    14  			segs: []segment{
    15  				literal("v1"),
    16  			},
    17  			want: "/v1",
    18  		},
    19  		{
    20  			segs: []segment{
    21  				wildcard{},
    22  			},
    23  			want: "/*",
    24  		},
    25  		{
    26  			segs: []segment{
    27  				deepWildcard{},
    28  			},
    29  			want: "/**",
    30  		},
    31  		{
    32  			segs: []segment{
    33  				variable{
    34  					path: "name",
    35  					segments: []segment{
    36  						literal("a"),
    37  					},
    38  				},
    39  			},
    40  			want: "/{name=a}",
    41  		},
    42  		{
    43  			segs: []segment{
    44  				variable{
    45  					path: "name",
    46  					segments: []segment{
    47  						literal("a"),
    48  						wildcard{},
    49  						literal("b"),
    50  					},
    51  				},
    52  			},
    53  			want: "/{name=a/*/b}",
    54  		},
    55  		{
    56  			segs: []segment{
    57  				literal("v1"),
    58  				variable{
    59  					path: "name",
    60  					segments: []segment{
    61  						literal("a"),
    62  						wildcard{},
    63  						literal("b"),
    64  					},
    65  				},
    66  				literal("c"),
    67  				variable{
    68  					path: "field.nested",
    69  					segments: []segment{
    70  						wildcard{},
    71  						literal("d"),
    72  					},
    73  				},
    74  				wildcard{},
    75  				literal("e"),
    76  				deepWildcard{},
    77  			},
    78  			want: "/v1/{name=a/*/b}/c/{field.nested=*/d}/*/e/**",
    79  		},
    80  	} {
    81  		tmpl := template{segments: spec.segs}
    82  		if got, want := tmpl.String(), spec.want; got != want {
    83  			t.Errorf("%#v.String() = %q; want %q", tmpl, got, want)
    84  		}
    85  
    86  		tmpl.verb = "LOCK"
    87  		if got, want := tmpl.String(), fmt.Sprintf("%s:LOCK", spec.want); got != want {
    88  			t.Errorf("%#v.String() = %q; want %q", tmpl, got, want)
    89  		}
    90  	}
    91  }
    92  

View as plain text