-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcallmeta_test.go
95 lines (85 loc) · 1.99 KB
/
callmeta_test.go
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// Copyright 2024 The Concerto Contributors.
// This source code is licensed under the Apache 2.0 license found
// in the LICENSE file in the root directory of this source tree.
// Copyright (c) The go-grpc-middleware Authors.
// Licensed under the Apache License 2.0.
package concerto_test
import (
"context"
"testing"
"github.com/gorhythm/concerto"
"github.com/gorhythm/concerto/transport"
)
func TestCallMeta_FullMethod(t *testing.T) {
callMeta := concerto.CallMeta{
Service: "concerto.test.v1.TestService",
Method: "Ping",
Transport: transport.TransportGRPC,
}
want := "concerto.test.v1.TestService/Ping"
got := callMeta.FullMethod()
if got != want {
t.Errorf("test failed. Got %q, want %q", got, want)
}
}
func TestCallMetaFromContext(t *testing.T) {
callMeta := concerto.CallMeta{
Service: "concerto.test.v1.TestService",
Method: "Ping",
Transport: transport.TransportGRPC,
}
type args struct {
ctx context.Context
}
tests := []struct {
name string
args args
want concerto.CallMeta
}{
{
name: "found",
args: args{
ctx: concerto.ContextWithCallMeta(context.Background(), callMeta),
},
want: callMeta,
},
{
name: "not found",
args: args{
ctx: context.Background(),
},
want: concerto.NilCallMeta,
},
{
name: "nil context",
args: args{
ctx: nil,
},
want: concerto.NilCallMeta,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := concerto.CallMetaFromContext(tt.args.ctx); got != tt.want {
t.Errorf(
"test %q failed. Got %+v, want %+v",
tt.name, got, tt.want,
)
}
})
}
}
func TestContextWithCallMeta(t *testing.T) {
callMeta := concerto.CallMeta{
Service: "concerto.test.v1.TestService",
Method: "Ping",
Transport: transport.TransportGRPC,
}
want := callMeta
got := concerto.CallMetaFromContext(
concerto.ContextWithCallMeta(context.Background(), callMeta),
)
if got != want {
t.Errorf("test failed. Got %+v, want %+v", got, want)
}
}