Conversation
47f8c76 to
ac3fd3a
Compare
| cfg := &Config{} | ||
| var missing []Capability | ||
|
|
||
| if slices.Contains(caps, KCPFrontProxyKubeconfig) { | ||
| v := os.Getenv(string(KCPFrontProxyKubeconfig)) | ||
| if v == "" { | ||
| missing = append(missing, KCPFrontProxyKubeconfig) | ||
| } else { | ||
| cfg.FrontProxyKubeconfig = loadKubeconfig(t, v) | ||
| } | ||
| } | ||
|
|
||
| if slices.Contains(caps, KCPShardKubeconfig) { | ||
| v := os.Getenv(string(KCPShardKubeconfig)) | ||
| if v == "" { | ||
| missing = append(missing, KCPShardKubeconfig) | ||
| } else { | ||
| cfg.ShardKubeconfig = loadKubeconfig(t, v) | ||
| } | ||
| } | ||
|
|
||
| if len(missing) > 0 { | ||
| t.Fatalf("Require: the following required environment variables are not set: %v", missing) | ||
| } |
There was a problem hiding this comment.
Wouldn't it be short to just require.NotEmpty cfg.FrontProxyKubeconfig?
if slices.Contains(caps, KCPFrontProxyKubeconfig) {
cfg.FrontProxyKubeconfig = os.Getenv(string(KCPFrontProxyKubeconfig))
require.NotEmpty(t, cfg.FrontProxyKubeconfig, "env var must be set", KCPFrontProxyKubeconfig))
}This should happen early enough that we don't need to check all settings first before failing.
There was a problem hiding this comment.
Hmm I really like the behavior that it immediately tells you all the variables that are missing. I expect over time for the list to grow quite large and when you run these tests as a pod somewhere, I think its convenient if the first error message just tells you everything.
What I could offer ot make it a bit more streamlined is something like this. Let me know if you have a strong preference on it over the other one.
cfg := &Config{}
var missing []Capability
setters := map[Capability]func(*rest.Config){
KCPFrontProxyKubeconfig: func(c *rest.Config) { cfg.FrontProxyKubeconfig = c },
KCPShardKubeconfig: func(c *rest.Config) { cfg.ShardKubeconfig = c },
}
for _, cap := range caps {
v := os.Getenv(string(cap))
if v == "" {
missing = append(missing, cap)
continue
}
setters[cap](loadKubeconfig(t, v))
}
require.Empty(t, missing, "the following required environment variables are not set: %v", missing)There was a problem hiding this comment.
You could also use a combination of assert and a boolean:
if slices.Contains(caps, KCPFrontProxyKubeconfig) {
cfg.FrontProxyKubeconfig = os.Getenv(string(KCPFrontProxyKubeconfig))
assert.NotEmpty(t, cfg.FrontProxyKubeconfig, "env var must be set", KCPFrontProxyKubeconfig))
anyMissing = true
}
// ...
require.False(t, anyMissing, "missing required components and/or settings")Keeps it streamlined while staying flexible to check if e.g. additional tooling is present if the configuration requires it.
There was a problem hiding this comment.
sorry might be Monday brain: But this would not work for the happy path or?
If I have the env set correctly then assert is fine, but we still would set anyMissing to true, even though it is not missing?
There was a problem hiding this comment.
Ah true :D I wasn't thinking correctly - but you can check on testing.T if it is already failed:
https://pkg.go.dev/testing#T.Failed
if slices.Contains(caps, KCPFrontProxyKubeconfig) {
cfg.FrontProxyKubeconfig = os.Getenv(string(KCPFrontProxyKubeconfig))
assert.NotEmpty(t, cfg.FrontProxyKubeconfig, "env var must be set", KCPFrontProxyKubeconfig))
}
// ...
require.False(t, t.Failed(), "missing required components and/or settings")ac3fd3a to
2f89683
Compare
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
/hold there is currently an issue where the unit-tests are passing, but skipping the unit-tests of the framework. I'll look into it, but for now hold the PR so we don't accidentally merge/forget about it. |
2f89683 to
d757aca
Compare
|
/unhold |
On-behalf-of: SAP <simon.bein@sap.com> Signed-off-by: Simon Bein <simontheleg@gmail.com>
d757aca to
63257cc
Compare
now that we also have it on main On-behalf-of: SAP <simon.bein@sap.com> Signed-off-by: Simon Bein <simontheleg@gmail.com>
|
/retest |
|
/restest |
Summary
This PR adds the loadtesting framework, considerations for review:
testing/example_test.gois a good starting point to see how all different aspects of the framework come togetherWhat Type of PR Is This?
/kind feature
Release Notes