github.com/matrixorigin/matrixone@v1.2.0/pkg/sql/plan/function/ctl/cmd_label_test.go (about) 1 // Copyright 2021 - 2023 Matrix Origin 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 package ctl 16 17 import ( 18 "testing" 19 20 "github.com/stretchr/testify/require" 21 ) 22 23 func TestIdentifyParser(t *testing.T) { 24 t.Run("success", func(t *testing.T) { 25 p := identifyParser("cn_1:k1:v1") 26 require.NotNil(t, p) 27 switch p.(type) { 28 case *singleValue: 29 default: 30 t.Fatalf("wrong type") 31 } 32 label := p.parseLabel() 33 require.Equal(t, "cn_1", label.uuid) 34 require.Equal(t, "k1", label.key) 35 require.Equal(t, []string{"v1"}, label.values) 36 37 p = identifyParser("cn_2:k2:[v1,v_2,v3]") 38 require.NotNil(t, p) 39 switch p.(type) { 40 case *multiValues: 41 default: 42 t.Fatalf("wrong type") 43 } 44 label = p.parseLabel() 45 require.Equal(t, "cn_2", label.uuid) 46 require.Equal(t, "k2", label.key) 47 require.Equal(t, []string{"v1", "v_2", "v3"}, label.values) 48 }) 49 50 t.Run("fails", func(t *testing.T) { 51 cases := []string{ 52 "&&&", 53 "aaa", 54 "a:b", 55 ":a:b:c", 56 "a::b:c", 57 "a:b::c", 58 "a: b:c", 59 "a:b:c:", 60 "a^:b:c", 61 "a:b-1:c", 62 "a:b:c-1", 63 "a:b:[]", 64 "a:b:[c:]", 65 "a:b:[c,d:]", 66 "a:b:[:]", 67 "a:b:[c,]", 68 "a:b:[c,d-1]", 69 "a:b:[c,d]]", 70 "a:b:[[c,d]", 71 } 72 for _, c := range cases { 73 p := identifyParser(c) 74 require.Nil(t, p) 75 } 76 }) 77 } 78 79 func TestHandleSetLabel(t *testing.T) { 80 // This case is tested in DebugUpdateCNLabel in clusterservice package. 81 }