(t *testing.T)
| 36 | const defaultTestTimeout = 10 * time.Second |
| 37 | |
| 38 | func (s) TestLog(t *testing.T) { |
| 39 | idGen.reset() |
| 40 | ml := NewTruncatingMethodLogger(10, 10) |
| 41 | // Set sink to testing buffer. |
| 42 | buf := bytes.NewBuffer(nil) |
| 43 | ml.sink = newWriterSink(buf) |
| 44 | |
| 45 | addr := "1.2.3.4" |
| 46 | port := 790 |
| 47 | tcpAddr, _ := net.ResolveTCPAddr("tcp", fmt.Sprintf("%v:%d", addr, port)) |
| 48 | addr6 := "2001:1db8:85a3::8a2e:1370:7334" |
| 49 | port6 := 796 |
| 50 | tcpAddr6, _ := net.ResolveTCPAddr("tcp", fmt.Sprintf("[%v]:%d", addr6, port6)) |
| 51 | |
| 52 | testProtoMsg := &binlogpb.Message{ |
| 53 | Length: 1, |
| 54 | Data: []byte{'a'}, |
| 55 | } |
| 56 | testProtoBytes, _ := proto.Marshal(testProtoMsg) |
| 57 | |
| 58 | testCases := []struct { |
| 59 | config LogEntryConfig |
| 60 | want *binlogpb.GrpcLogEntry |
| 61 | }{ |
| 62 | { |
| 63 | config: &ClientHeader{ |
| 64 | OnClientSide: false, |
| 65 | Header: map[string][]string{ |
| 66 | "a": {"b", "bb"}, |
| 67 | }, |
| 68 | MethodName: "testservice/testmethod", |
| 69 | Authority: "test.service.io", |
| 70 | Timeout: 2*time.Second + 3*time.Nanosecond, |
| 71 | PeerAddr: tcpAddr, |
| 72 | }, |
| 73 | want: &binlogpb.GrpcLogEntry{ |
| 74 | Timestamp: nil, |
| 75 | CallId: 1, |
| 76 | SequenceIdWithinCall: 0, |
| 77 | Type: binlogpb.GrpcLogEntry_EVENT_TYPE_CLIENT_HEADER, |
| 78 | Logger: binlogpb.GrpcLogEntry_LOGGER_SERVER, |
| 79 | Payload: &binlogpb.GrpcLogEntry_ClientHeader{ |
| 80 | ClientHeader: &binlogpb.ClientHeader{ |
| 81 | Metadata: &binlogpb.Metadata{ |
| 82 | Entry: []*binlogpb.MetadataEntry{ |
| 83 | {Key: "a", Value: []byte{'b'}}, |
| 84 | {Key: "a", Value: []byte{'b', 'b'}}, |
| 85 | }, |
| 86 | }, |
| 87 | MethodName: "testservice/testmethod", |
| 88 | Authority: "test.service.io", |
| 89 | Timeout: &durationpb.Duration{ |
| 90 | Seconds: 2, |
| 91 | Nanos: 3, |
| 92 | }, |
| 93 | }, |
| 94 | }, |
| 95 | PayloadTruncated: false, |
nothing calls this directly
no test coverage detected