github.com/looshlee/beatles@v0.0.0-20220727174639-742810ab631c/pkg/metrics/middleware_test.go (about)

     1  // Copyright 2019 Authors of Cilium
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  // +build !privileged_tests
    16  
    17  package metrics
    18  
    19  import (
    20  	"testing"
    21  
    22  	. "gopkg.in/check.v1"
    23  )
    24  
    25  // Hook up gocheck into the "go test" runner.
    26  func Test(t *testing.T) {
    27  	TestingT(t)
    28  }
    29  
    30  type MetricsSuite struct{}
    31  
    32  var _ = Suite(&MetricsSuite{})
    33  
    34  func (s *MetricsSuite) Test_getShortPath(c *C) {
    35  	tests := []struct {
    36  		args string
    37  		want string
    38  	}{
    39  		{
    40  			args: "/v1/config",
    41  			want: "/v1/config",
    42  		},
    43  		{
    44  			args: "/v1/endpoint/cilium-local:0",
    45  			want: "/v1/endpoint",
    46  		},
    47  		{
    48  			args: "/v1/endpoint/container-id:597b3583727d51206d0a08df82b484925b458ff1fc04d1a98637435b73b9b47d",
    49  			want: "/v1/endpoint",
    50  		},
    51  		{
    52  			args: "/v1/endpoint/container-id:6813916d21c3311e62078a232942504937f1b4a8b2e32e40044f188da986fe41",
    53  			want: "/v1/endpoint",
    54  		},
    55  		{
    56  			args: "/v1/endpoint/container-id:cf2c692f24933fc12d51dc0b42d92708a3c73e8f3a0f517c3ed2e7628ba57d92",
    57  			want: "/v1/endpoint",
    58  		},
    59  		{
    60  			args: "/v1/healthz",
    61  			want: "/v1/healthz",
    62  		},
    63  		{
    64  			args: "/v1/ipam",
    65  			want: "/v1/ipam",
    66  		},
    67  		{
    68  			args: "/v1/ipam/10.16.11.109",
    69  			want: "/v1/ipam",
    70  		},
    71  		{
    72  			args: "/v1/ipam/10.16.169.230",
    73  			want: "/v1/ipam",
    74  		},
    75  		{
    76  			args: "/v1/ipam/10.16.69.17",
    77  			want: "/v1/ipam",
    78  		},
    79  		{
    80  			args: "/v1/ipam/f00d::a10:0:0:2f5f",
    81  			want: "/v1/ipam",
    82  		},
    83  		{
    84  			args: "/v1/ipam/f00d::a10:0:0:9dec",
    85  			want: "/v1/ipam",
    86  		},
    87  		{
    88  			args: "/v1/ipam/f00d::a10:0:0:d5c7",
    89  			want: "/v1/ipam",
    90  		},
    91  		{
    92  			args: "/v1/ipam/f00d::a10:0:0:d5c7/hello",
    93  			want: "/v1/ipam",
    94  		},
    95  		{
    96  			args: "/v1",
    97  			want: "/v1",
    98  		},
    99  		{
   100  			args: "/////",
   101  			want: "//",
   102  		},
   103  		{
   104  			args: "//",
   105  			want: "//",
   106  		},
   107  		{
   108  			args: "/",
   109  			want: "/",
   110  		},
   111  		{
   112  			args: "hello/foo/bar/",
   113  			want: "hello/foo/bar",
   114  		},
   115  		{
   116  			args: "hello/foo//",
   117  			want: "hello/foo/",
   118  		},
   119  		{
   120  			args: "hello/foo/",
   121  			want: "hello/foo/",
   122  		},
   123  		{
   124  			args: "hello/foo",
   125  			want: "hello/foo",
   126  		},
   127  		{
   128  			args: "hello/",
   129  			want: "hello/",
   130  		},
   131  		{
   132  			args: "hello",
   133  			want: "hello",
   134  		},
   135  		{
   136  			args: "",
   137  			want: "",
   138  		},
   139  	}
   140  	for _, tt := range tests {
   141  		got := getShortPath(tt.args)
   142  		c.Assert(got, Equals, tt.want)
   143  	}
   144  }