trpc.group/trpc-go/trpc-go@v1.0.3/client/attachment_test.go (about) 1 // 2 // 3 // Tencent is pleased to support the open source community by making tRPC available. 4 // 5 // Copyright (C) 2023 THL A29 Limited, a Tencent company. 6 // All rights reserved. 7 // 8 // If you have downloaded a copy of the tRPC source code from Tencent, 9 // please note that tRPC source code is licensed under the Apache 2.0 License, 10 // A copy of the Apache 2.0 License is included in this file. 11 // 12 // 13 14 package client 15 16 import ( 17 "bytes" 18 "context" 19 "io" 20 "testing" 21 22 "github.com/stretchr/testify/require" 23 24 "trpc.group/trpc-go/trpc-go/codec" 25 "trpc.group/trpc-go/trpc-go/internal/attachment" 26 ) 27 28 func TestAttachment(t *testing.T) { 29 attm := NewAttachment(bytes.NewReader([]byte("attachment"))) 30 require.Equal(t, attachment.NoopAttachment{}, attm.Response()) 31 msg := codec.Message(context.Background()) 32 setAttachment(msg, &attm.attachment) 33 attcher, ok := attachment.ClientRequestAttachment(msg) 34 require.True(t, ok) 35 bts, err := io.ReadAll(attcher) 36 require.Nil(t, err) 37 require.Equal(t, []byte("attachment"), bts) 38 }