|
| 1 | +package meta |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "testing" |
| 6 | + |
| 7 | + "github.com/stretchr/testify/require" |
| 8 | + "google.golang.org/grpc/metadata" |
| 9 | +) |
| 10 | + |
| 11 | +func TestContext(t *testing.T) { |
| 12 | + for _, tt := range []struct { |
| 13 | + name string |
| 14 | + ctx context.Context |
| 15 | + header string |
| 16 | + values []string |
| 17 | + }{ |
| 18 | + { |
| 19 | + name: "WithApplicationName", |
| 20 | + ctx: WithApplicationName(context.Background(), "test"), |
| 21 | + header: HeaderApplicationName, |
| 22 | + values: []string{"test"}, |
| 23 | + }, |
| 24 | + { |
| 25 | + name: "WithTraceID", |
| 26 | + ctx: WithTraceID(context.Background(), "my-trace-id"), |
| 27 | + header: HeaderTraceID, |
| 28 | + values: []string{"my-trace-id"}, |
| 29 | + }, |
| 30 | + { |
| 31 | + name: "WithRequestType", |
| 32 | + ctx: WithRequestType(context.Background(), "my-request-type"), |
| 33 | + header: HeaderRequestType, |
| 34 | + values: []string{"my-request-type"}, |
| 35 | + }, |
| 36 | + { |
| 37 | + name: "WithAllowFeatures", |
| 38 | + ctx: WithAllowFeatures(context.Background(), "feature-1", "feature-2", "feature-3"), |
| 39 | + header: HeaderClientCapabilities, |
| 40 | + values: []string{"feature-1", "feature-2", "feature-3"}, |
| 41 | + }, |
| 42 | + } { |
| 43 | + t.Run(tt.name, func(t *testing.T) { |
| 44 | + md, has := metadata.FromOutgoingContext(tt.ctx) |
| 45 | + require.True(t, has) |
| 46 | + require.Equal(t, tt.values, md.Get(tt.header)) |
| 47 | + }) |
| 48 | + } |
| 49 | +} |
0 commit comments