github.com/polarismesh/polaris@v1.17.8/common/utils/common_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 utils 19 20 import ( 21 "testing" 22 23 "github.com/golang/protobuf/ptypes/wrappers" 24 ) 25 26 // TestCheckResourceName tests the checkResourceName function 27 func TestCheckResourceName(t *testing.T) { 28 type args struct { 29 name *wrappers.StringValue 30 } 31 tests := []struct { 32 name string 33 args args 34 wantErr bool 35 }{ 36 {name: "nil test", args: args{ 37 name: nil, 38 }, wantErr: true}, 39 {name: "empty test", args: args{ 40 name: &wrappers.StringValue{Value: ""}, 41 }, wantErr: true}, 42 {name: "illegal treatment", args: args{ 43 name: &wrappers.StringValue{Value: "a-b-c-d-#"}, 44 }, wantErr: true}, 45 {name: "normal treatment", args: args{ 46 name: &wrappers.StringValue{Value: "a-b-c-d"}, 47 }, wantErr: false}, 48 {name: "normal treatment-backslash", args: args{ 49 name: &wrappers.StringValue{Value: "/a/b/c/d"}, 50 }, wantErr: false}, 51 } 52 for _, tt := range tests { 53 t.Run(tt.name, func(t *testing.T) { 54 if err := CheckResourceName(tt.args.name); (err != nil) != tt.wantErr { 55 t.Errorf("CheckResourceName() error = %v, wantErr %v", err, tt.wantErr) 56 } 57 }) 58 } 59 }