-
Notifications
You must be signed in to change notification settings - Fork 132
Expand file tree
/
Copy pathattachment_test.go
More file actions
40 lines (34 loc) · 1 KB
/
attachment_test.go
File metadata and controls
40 lines (34 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//
//
// Tencent is pleased to support the open source community by making tRPC available.
//
// Copyright (C) 2023 Tencent.
// All rights reserved.
//
// If you have downloaded a copy of the tRPC source code from Tencent,
// please note that tRPC source code is licensed under the Apache 2.0 License,
// A copy of the Apache 2.0 License is included in this file.
//
//
package server_test
import (
"bytes"
"context"
"io"
"testing"
"github.com/stretchr/testify/require"
trpc "trpc.group/trpc-go/trpc-go"
"trpc.group/trpc-go/trpc-go/internal/attachment"
"trpc.group/trpc-go/trpc-go/server"
)
func TestAttachment(t *testing.T) {
msg := trpc.Message(context.Background())
attm := server.GetAttachment(msg)
require.Equal(t, attachment.NoopAttachment{}, attm.Request())
attm.SetResponse(bytes.NewReader([]byte("attachment")))
responseAttm, ok := attachment.ServerResponseAttachment(msg)
require.True(t, ok)
bts, err := io.ReadAll(responseAttm)
require.Nil(t, err)
require.Equal(t, []byte("attachment"), bts)
}