github.com/cloudwego/kitex@v0.9.0/pkg/generic/pbidl_provider_test.go (about) 1 /* 2 * Copyright 2021 CloudWeGo Authors 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package generic 18 19 import ( 20 "context" 21 "testing" 22 23 dproto "github.com/cloudwego/dynamicgo/proto" 24 25 "github.com/cloudwego/kitex/internal/test" 26 ) 27 28 func TestPbContentProvider(t *testing.T) { 29 path := "a/b/main.proto" 30 content := ` 31 package kitex.test.server; 32 import "a/b/x.proto"; 33 import "a/y.proto"; 34 35 service InboxService {} 36 ` 37 includes := map[string]string{ 38 path: content, 39 "a/b/x.proto": "package kitex.test.server;", 40 "a/y.proto": ` 41 package kitex.test.server; 42 import "a/z.proto"; 43 `, 44 "a/z.proto": "package kitex.test.server;", 45 } 46 p, err := NewPbContentProvider(path, includes) 47 test.Assert(t, err == nil) 48 tree := <-p.Provide() 49 test.Assert(t, tree != nil) 50 } 51 52 func TestPbContentProviderDynamicGo(t *testing.T) { 53 path := "./jsonpb_test/idl/echo.proto" 54 55 opts := dproto.Options{} 56 p, err := NewPbFileProviderWithDynamicGo(path, context.Background(), opts) 57 58 test.Assert(t, err == nil) 59 60 svcDsc := <-p.Provide() 61 test.Assert(t, svcDsc != nil) 62 }