New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ringhash: allow overriding max ringhash size via environment variable #5884
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* | ||
* Copyright 2022 gRPC authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
package envconfig | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"google.golang.org/grpc/internal/grpctest" | ||
) | ||
|
||
type s struct { | ||
grpctest.Tester | ||
} | ||
|
||
func Test(t *testing.T) { | ||
grpctest.RunSubTests(t, s{}) | ||
} | ||
|
||
func (s) TestUint64FromEnv(t *testing.T) { | ||
|
||
var testCases = []struct { | ||
name string | ||
val string | ||
def, min, max uint64 | ||
want uint64 | ||
}{ | ||
{ | ||
name: "error parsing; want default", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we change the test names to be in snake_case instead, as the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is fine IMO. AFAICT there's no real guidance given on this by the Go team, and the name is essentially just a convenience & informational. No matter what we name things, they will be copy-pasteable to re-run. That said, the "want"s are pretty obvious, especially given the "want" declaration, so I just removed them. |
||
val: "asdf", def: 5, want: 5, | ||
}, { | ||
name: "unset; want default", | ||
val: "", def: 5, want: 5, | ||
}, { | ||
name: "too low; want min", | ||
val: "5", min: 10, want: 10, | ||
}, { | ||
name: "too high; want max", | ||
val: "5", max: 2, want: 2, | ||
}, { | ||
name: "in range; good", | ||
val: "17391", def: 13000, min: 12000, max: 18000, want: 17391, | ||
}, | ||
} | ||
for _, tc := range testCases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
const testVar = "testvar" | ||
if tc.val == "" { | ||
os.Unsetenv(testVar) | ||
Comment on lines
+64
to
+65
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we really need this special case for empty string? Since the code which reads the env var uses There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From a blackbox testing perspective, it's an interesting, specific test. But from a whitebox perspective, it's no different. So I could go either way, but I'm inclined to keep it with the former in mind. |
||
} else { | ||
os.Setenv(testVar, tc.val) | ||
} | ||
if got := uint64FromEnv(testVar, tc.def, tc.min, tc.max); got != tc.want { | ||
t.Errorf("uint64FromEnv(%q(=%q), %v, %v, %v) = %v; want %v", testVar, tc.val, tc.def, tc.min, tc.max, got, tc.want) | ||
} | ||
}) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: s/XDSRingHashCap/RingHashCap
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not just a nit; vet won't pass like this. Fixed.