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

Method TestParseConfig

balancer/rls/config_test.go:51–212  ·  view source on GitHub ↗

TestParseConfig verifies successful config parsing scenarios.

(t *testing.T)

Source from the content-addressed store, hash-verified

49
50// TestParseConfig verifies successful config parsing scenarios.
51func (s) TestParseConfig(t *testing.T) {
52 childPolicyTargetFieldVal, _ := json.Marshal(dummyChildPolicyTarget)
53 tests := []struct {
54 desc string
55 input []byte
56 wantCfg *lbConfig
57 }{
58 {
59 // This input validates a few cases:
60 // - A top-level unknown field should not fail.
61 // - An unknown field in routeLookupConfig proto should not fail.
62 // - lookupServiceTimeout is set to its default value, since it is not specified in the input.
63 // - maxAge is clamped to maxMaxAge if staleAge is not set.
64 // - staleAge is ignored because it is higher than maxAge in the input.
65 // - cacheSizeBytes is greater than the hard upper limit of 5MB
66 desc: "with transformations 1",
67 input: []byte(`{
68 "top-level-unknown-field": "unknown-value",
69 "routeLookupConfig": {
70 "unknown-field": "unknown-value",
71 "grpcKeybuilders": [{
72 "names": [{"service": "service", "method": "method"}],
73 "headers": [{"key": "k1", "names": ["v1"]}]
74 }],
75 "lookupService": ":///target",
76 "maxAge" : "500s",
77 "staleAge": "600s",
78 "cacheSizeBytes": 100000000,
79 "defaultTarget": "passthrough:///default"
80 },
81 "childPolicy": [
82 {"cds_experimental": {"Cluster": "my-fav-cluster"}},
83 {"unknown-policy": {"unknown-field": "unknown-value"}},
84 {"grpclb": {"childPolicy": [{"pickfirst": {}}]}}
85 ],
86 "childPolicyConfigTargetFieldName": "serviceName"
87 }`),
88 wantCfg: &lbConfig{
89 lookupService: ":///target",
90 lookupServiceTimeout: 10 * time.Second, // This is the default value.
91 maxAge: 500 * time.Second, // Max age is not clamped when stale age is set.
92 staleAge: 300 * time.Second, // StaleAge is clamped because it was higher than maxMaxAge.
93 cacheSizeBytes: maxCacheSize,
94 defaultTarget: "passthrough:///default",
95 childPolicyName: "grpclb",
96 childPolicyTargetField: "serviceName",
97 childPolicyConfig: map[string]json.RawMessage{
98 "childPolicy": json.RawMessage(`[{"pickfirst": {}}]`),
99 "serviceName": json.RawMessage(childPolicyTargetFieldVal),
100 },
101 },
102 },
103 {
104 desc: "maxAge not clamped when staleAge is set",
105 input: []byte(`{
106 "routeLookupConfig": {
107 "grpcKeybuilders": [{
108 "names": [{"service": "service", "method": "method"}],

Callers

nothing calls this directly

Calls 4

ParseConfigMethod · 0.95
testEqualFunction · 0.85
MarshalMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected