github.com/cloudwego/kitex@v0.9.0/pkg/rpcinfo/copy_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 rpcinfo 18 19 import ( 20 "context" 21 "testing" 22 23 "github.com/cloudwego/kitex/internal/test" 24 ) 25 26 func TestFreezeRPCInfo(t *testing.T) { 27 ri := NewRPCInfo( 28 EmptyEndpointInfo(), 29 EmptyEndpointInfo(), 30 NewInvocation("service", "method"), 31 NewRPCConfig(), 32 NewRPCStats(), 33 ) 34 ctx := NewCtxWithRPCInfo(context.Background(), ri) 35 36 test.Assert(t, AsTaggable(ri.From()) != nil) 37 test.Assert(t, AsTaggable(ri.To()) != nil) 38 test.Assert(t, AsMutableEndpointInfo(ri.From()) != nil) 39 test.Assert(t, AsMutableEndpointInfo(ri.To()) != nil) 40 test.Assert(t, AsMutableRPCConfig(ri.Config()) != nil) 41 test.Assert(t, AsMutableRPCStats(ri.Stats()) != nil) 42 43 ctx2 := FreezeRPCInfo(ctx) 44 test.Assert(t, ctx2 != ctx) 45 ri2 := GetRPCInfo(ctx2) 46 test.Assert(t, ri2 != nil) 47 test.Assert(t, ri2 != ri) 48 49 test.Assert(t, AsTaggable(ri2.From()) == nil) 50 test.Assert(t, AsTaggable(ri2.To()) == nil) 51 test.Assert(t, AsMutableEndpointInfo(ri2.From()) == nil) 52 test.Assert(t, AsMutableEndpointInfo(ri2.To()) == nil) 53 test.Assert(t, AsMutableRPCConfig(ri2.Config()) == nil) 54 test.Assert(t, ri2.Stats() == nil) 55 }