github.com/cloudwego/kitex@v0.9.0/tool/internal_pkg/pluginmode/thriftgo/hessian2_test.go (about) 1 // Copyright 2024 CloudWeGo Authors 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 thriftgo 16 17 import ( 18 "io" 19 "reflect" 20 "strings" 21 "testing" 22 23 "github.com/cloudwego/kitex/internal/test" 24 25 "github.com/cloudwego/thriftgo/config" 26 ) 27 28 func Test_loadIDLRefConfig(t *testing.T) { 29 testCases := []struct { 30 desc string 31 reader io.Reader 32 expected func(t *testing.T, res *config.RawConfig) 33 }{ 34 { 35 desc: "normal idl-ref file", 36 reader: strings.NewReader(`ref: 37 decimal.thrift: dubbo-demo/decimal 38 java.thrift: github.com/kitex-contrib/codec-dubbo/java 39 debug: false`), 40 expected: func(t *testing.T, res *config.RawConfig) { 41 test.Assert(t, reflect.DeepEqual(res, &config.RawConfig{ 42 Ref: map[string]interface{}{ 43 "decimal.thrift": "dubbo-demo/decimal", 44 "java.thrift": "github.com/kitex-contrib/codec-dubbo/java", 45 }, 46 Debug: false, 47 })) 48 }, 49 }, 50 { 51 desc: "empty idl-ref file", 52 reader: strings.NewReader(""), 53 expected: func(t *testing.T, res *config.RawConfig) { 54 test.Assert(t, len(res.Ref) == 0, res.Ref) 55 test.Assert(t, res.Debug == false, res.Debug) 56 }, 57 }, 58 } 59 60 for _, tc := range testCases { 61 t.Run(tc.desc, func(t *testing.T) { 62 res := loadIDLRefConfig("", tc.reader) 63 tc.expected(t, res) 64 }) 65 } 66 }