MCPcopy
hub / github.com/grpc/grpc-go / TestNewLoggerFromConfigString

Method TestNewLoggerFromConfigString

internal/binarylog/env_config_test.go:28–66  ·  view source on GitHub ↗

This tests that when multiple configs are specified, all methods loggers will be set correctly. Correctness of each logger is covered by other unit tests.

(t *testing.T)

Source from the content-addressed store, hash-verified

26// This tests that when multiple configs are specified, all methods loggers will
27// be set correctly. Correctness of each logger is covered by other unit tests.
28func (s) TestNewLoggerFromConfigString(t *testing.T) {
29 const (
30 s1 = "s1"
31 m1 = "m1"
32 m2 = "m2"
33 fullM1 = s1 + "/" + m1
34 fullM2 = s1 + "/" + m2
35 )
36 c := fmt.Sprintf("*{h:1;m:2},%s{h},%s{m},%s{h;m}", s1+"/*", fullM1, fullM2)
37 l := NewLoggerFromConfigString(c).(*logger)
38
39 if l.config.All.Header != 1 || l.config.All.Message != 2 {
40 t.Errorf("l.config.All = %#v, want headerLen: 1, messageLen: 2", l.config.All)
41 }
42
43 if ml, ok := l.config.Services[s1]; ok {
44 if ml.Header != maxUInt || ml.Message != 0 {
45 t.Errorf("want maxUInt header, 0 message, got header: %v, message: %v", ml.Header, ml.Message)
46 }
47 } else {
48 t.Errorf("service/* is not set")
49 }
50
51 if ml, ok := l.config.Methods[fullM1]; ok {
52 if ml.Header != 0 || ml.Message != maxUInt {
53 t.Errorf("want 0 header, maxUInt message, got header: %v, message: %v", ml.Header, ml.Message)
54 }
55 } else {
56 t.Errorf("service/method{h} is not set")
57 }
58
59 if ml, ok := l.config.Methods[fullM2]; ok {
60 if ml.Header != maxUInt || ml.Message != maxUInt {
61 t.Errorf("want maxUInt header, maxUInt message, got header: %v, message: %v", ml.Header, ml.Message)
62 }
63 } else {
64 t.Errorf("service/method{h;m} is not set")
65 }
66}
67
68func (s) TestNewLoggerFromConfigStringInvalid(t *testing.T) {
69 testCases := []string{

Callers

nothing calls this directly

Calls 2

ErrorfMethod · 0.65

Tested by

no test coverage detected