github.com/cloudwego/kitex@v0.9.0/tool/internal_pkg/generator/template_test.go (about) 1 // Copyright 2022 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 generator 16 17 import ( 18 "testing" 19 20 "github.com/cloudwego/kitex/internal/test" 21 ) 22 23 func TestNilSafe(t *testing.T) { 24 var q *TemplateExtension 25 fn := "/tmp/kitex-template-nil.json" 26 27 err := q.ToJSONFile(fn) 28 test.Assert(t, err == nil, err) 29 30 err = q.FromJSONFile(fn) 31 test.Assert(t, err == nil, err) 32 } 33 34 func TestMarshal(t *testing.T) { 35 p := &TemplateExtension{ 36 FeatureNames: []string{"f1", "f2"}, 37 EnableFeatures: []string{"f1"}, 38 Dependencies: map[string]string{ 39 "example.com/demo": "demo", 40 "example.com/test": "test2", 41 }, 42 ExtendClient: &APIExtension{ 43 ImportPaths: []string{"example.com/demo"}, 44 ExtendOption: "option...", 45 ExtendFile: "file...", 46 }, 47 ExtendServer: &APIExtension{ 48 ImportPaths: []string{"example.com/demo"}, 49 ExtendOption: "option...", 50 ExtendFile: "file...", 51 }, 52 ExtendInvoker: &APIExtension{ 53 ImportPaths: []string{"example.com/demo"}, 54 ExtendOption: "option...", 55 ExtendFile: "file...", 56 }, 57 } 58 59 fn := "/tmp/kitex-template.json" 60 err := p.ToJSONFile(fn) 61 test.Assert(t, err == nil, err) 62 63 q := new(TemplateExtension) 64 err = q.FromJSONFile(fn) 65 test.Assert(t, err == nil, err) 66 67 test.DeepEqual(t, p, q) 68 }