github.com/polarismesh/polaris@v1.17.8/cache/service/service_query_test.go (about)

     1  /**
     2   * Tencent is pleased to support the open source community by making Polaris available.
     3   *
     4   * Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
     5   *
     6   * Licensed under the BSD 3-Clause License (the "License");
     7   * you may not use this file except in compliance with the License.
     8   * You may obtain a copy of the License at
     9   *
    10   * https://opensource.org/licenses/BSD-3-Clause
    11   *
    12   * Unless required by applicable law or agreed to in writing, software distributed
    13   * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
    14   * CONDITIONS OF ANY KIND, either express or implied. See the License for the
    15   * specific language governing permissions and limitations under the License.
    16   */
    17  
    18  package service
    19  
    20  import (
    21  	"testing"
    22  
    23  	"github.com/polarismesh/polaris/common/model"
    24  )
    25  
    26  func Test_matchServiceFilter_ignoreServiceCI(t *testing.T) {
    27  	type args struct {
    28  		svc       *model.Service
    29  		svcFilter map[string]string
    30  		matchName bool
    31  	}
    32  	tests := []struct {
    33  		name string
    34  		args args
    35  		want bool
    36  	}{
    37  		{
    38  			name: "Test_1",
    39  			args: args{
    40  				svc: &model.Service{
    41  					Namespace: "default",
    42  					Name:      "TestCaseService",
    43  				},
    44  				svcFilter: map[string]string{
    45  					"name": "TestCaseService*",
    46  				},
    47  				matchName: true,
    48  			},
    49  			want: true,
    50  		},
    51  		{
    52  			name: "Test_1",
    53  			args: args{
    54  				svc: &model.Service{
    55  					Namespace: "default",
    56  					Name:      "TestCaseService",
    57  				},
    58  				svcFilter: map[string]string{
    59  					"name": "testCaseService*",
    60  				},
    61  				matchName: true,
    62  			},
    63  			want: true,
    64  		},
    65  		{
    66  			name: "Test_1",
    67  			args: args{
    68  				svc: &model.Service{
    69  					Namespace: "default",
    70  					Name:      "TestCaseService",
    71  				},
    72  				svcFilter: map[string]string{
    73  					"name": "testCase*",
    74  				},
    75  				matchName: true,
    76  			},
    77  			want: true,
    78  		},
    79  		{
    80  			name: "Test_1",
    81  			args: args{
    82  				svc: &model.Service{
    83  					Namespace: "default",
    84  					Name:      "TestCaseService",
    85  				},
    86  				svcFilter: map[string]string{
    87  					"name": "Testcase*",
    88  				},
    89  				matchName: true,
    90  			},
    91  			want: true,
    92  		},
    93  	}
    94  	for _, tt := range tests {
    95  		t.Run(tt.name, func(t *testing.T) {
    96  			if got := matchServiceFilter(tt.args.svc, tt.args.svcFilter, tt.args.matchName, false); got != tt.want {
    97  				t.Errorf("matchServiceFilter() = %v, want %v", got, tt.want)
    98  			}
    99  		})
   100  	}
   101  }
   102  
   103  func Test_matchServiceFilter_business(t *testing.T) {
   104  	type args struct {
   105  		svc       *model.Service
   106  		svcFilter map[string]string
   107  		matchName bool
   108  	}
   109  	tests := []struct {
   110  		name string
   111  		args args
   112  		want bool
   113  	}{
   114  		{
   115  			name: "Test_1",
   116  			args: args{
   117  				svc: &model.Service{
   118  					Namespace: "default",
   119  					Business:  "TSE",
   120  				},
   121  				svcFilter: map[string]string{
   122  					"business": "TSE",
   123  				},
   124  				matchName: false,
   125  			},
   126  			want: true,
   127  		},
   128  		{
   129  			name: "Test_1",
   130  			args: args{
   131  				svc: &model.Service{
   132  					Namespace: "default",
   133  					Business:  "TSE",
   134  				},
   135  				svcFilter: map[string]string{
   136  					"business": "tse",
   137  				},
   138  				matchName: false,
   139  			},
   140  			want: true,
   141  		},
   142  		{
   143  			name: "Test_1",
   144  			args: args{
   145  				svc: &model.Service{
   146  					Namespace: "default",
   147  					Business:  "TSe",
   148  				},
   149  				svcFilter: map[string]string{
   150  					"business": "tse",
   151  				},
   152  				matchName: false,
   153  			},
   154  			want: true,
   155  		},
   156  		{
   157  			name: "Test_1",
   158  			args: args{
   159  				svc: &model.Service{
   160  					Namespace: "default",
   161  					Business:  "Te",
   162  				},
   163  				svcFilter: map[string]string{
   164  					"business": "tse",
   165  				},
   166  				matchName: false,
   167  			},
   168  			want: false,
   169  		},
   170  	}
   171  	for _, tt := range tests {
   172  		t.Run(tt.name, func(t *testing.T) {
   173  			if got := matchServiceFilter(tt.args.svc, tt.args.svcFilter, tt.args.matchName, false); got != tt.want {
   174  				t.Errorf("matchServiceFilter() = %v, want %v, args %#v", got, tt.want, tt.args)
   175  			}
   176  		})
   177  	}
   178  }