-
Notifications
You must be signed in to change notification settings - Fork 38
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
🐛 Ensure the environment.InitFlags()
is called to avoid confusion.
#269
Conversation
Also, moving code to TestMain() to avoid side effects, while importing a package.
/retest |
test/example/main_test.go
Outdated
@@ -38,13 +38,11 @@ import ( | |||
// config as well as the parsing level and state flags. | |||
var global environment.GlobalEnvironment | |||
|
|||
func init() { | |||
// TestMain is the first entry point for `go test`. | |||
func TestMain(m *testing.M) { | |||
// environment.InitFlags registers state and level filter flags. | |||
environment.InitFlags(flag.CommandLine) |
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.
I'm surprised InitFlags
isn't instanced - ie. we use local variable vs. package ones global.InitFlags
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.
Can you elaborate on this? I do not follow...
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.
InitFlags
is initializing package global variables in reconciler-test
When it could simply just modify values on the declared global
environment in the example. At least reconciler-test vars aren't exposed publicly so maybe that's ok. 🤷
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.
Yes. I agree such refactor would be beneficial. Mind opening an issue to track it?
there's a conflict with HEAD /lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: cardil, dprotaso The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/retest |
…-flags Conflicts fixed: * README.md * pkg/feature/level.go * pkg/feature/states.go * test/e2e/main_test.go * test/example/main_test.go
New changes are detected. LGTM label has been removed. |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: cardil, dprotaso The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
@dprotaso Could you slap the PR again? |
This Pull Request is stale because it has been open for 90 days with |
/reopen |
@cardil: Reopened this PR. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
f06f7cb
to
4cb6a34
Compare
/cc @pierDipi |
// levelPowerset returns all combinations for a given array. | ||
func levelPowerset(set []feature.Levels) (subsets [][]feature.Levels) { | ||
length := uint(len(set)) | ||
|
||
// Go through all possible combinations of objects | ||
// from 1 (only first object in subset) to 2^length (all objects in subset) | ||
for subsetBits := 1; subsetBits < (1 << length); subsetBits++ { | ||
var subset []feature.Levels | ||
|
||
for object := uint(0); object < length; object++ { | ||
// checks if object is contained in subset | ||
// by checking if bit 'object' is set in subsetBits | ||
if (subsetBits>>object)&1 == 1 { | ||
// add object to subset | ||
subset = append(subset, set[object]) | ||
} | ||
} | ||
// add subset to subsets | ||
subsets = append(subsets, subset) | ||
} | ||
return subsets | ||
} | ||
|
||
func levelBitwiseOr(subsets [][]feature.Levels) []feature.Levels { | ||
levels := make([]feature.Levels, len(subsets)) | ||
for i, subset := range subsets { | ||
val := 0 | ||
for _, level := range subset { | ||
val |= int(level) | ||
} | ||
levels[i] = feature.Levels(val) | ||
} | ||
return levels | ||
} |
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.
This is complex and hard to read code, what's the value of running all combinations when testing the boundaries is just enough?
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.
This code computes the all bitwise combinations of all levels. For example: MUST|MUST_NOT|SHOULD
or MAY|MUST
or just MUST
.
How about I add such doc to the test? WDYT?
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.
I think this is solved in 7bd94c5
func statePowerset(set []feature.States) (subsets [][]feature.States) { | ||
length := uint(len(set)) | ||
|
||
// Go through all possible combinations of objects | ||
// from 1 (only first object in subset) to 2^length (all objects in subset) | ||
for subsetBits := 1; subsetBits < (1 << length); subsetBits++ { | ||
var subset []feature.States | ||
|
||
for object := uint(0); object < length; object++ { | ||
// checks if object is contained in subset | ||
// by checking if bit 'object' is set in subsetBits | ||
if (subsetBits>>object)&1 == 1 { | ||
// add object to subset | ||
subset = append(subset, set[object]) | ||
} | ||
} | ||
// add subset to subsets | ||
subsets = append(subsets, subset) | ||
} | ||
return subsets | ||
} | ||
|
||
func stateBitwiseOr(subsets [][]feature.States) []feature.States { | ||
levels := make([]feature.States, len(subsets)) | ||
for i, subset := range subsets { | ||
val := 0 | ||
for _, state := range subset { | ||
val |= int(state) | ||
} | ||
levels[i] = feature.States(val) | ||
} | ||
return levels | ||
} |
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.
Same here, very hard to read and follow
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.
I think this is solved in 7bd94c5
// Valid checks if given level is valid (not empty combination of Levels values). | ||
func (l Levels) Valid() bool { | ||
val := uint8(l) | ||
if val == 0 { | ||
return false | ||
} | ||
val &^= uint8(All) | ||
return val == 0 | ||
} |
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.
I'd like to reduce bit manipulation as much as possible, a simple:
levels := sets.NewInt32(
int32(All),
int32(Must),
int32(MustNot),
int32(Should),
int32(ShouldNot),
int32(May),
)
return levels.Has(int32(l))
is much more readable and can go a long way
Same comment for Valid for States
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.
It's not the same. Now, you could use bitwise or to select multiple levels or states.
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.
Isn't this an input from command line? how do you do bitwise from command line?
That suggests that the type is wrong and shouldn't be a single value but rather an array
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.
No. You could invoke any number of those levels and features. See the code:
Just call the tests with those flags or states:
-feature.alpha -feature.beta -requirement.must -requirement.should -requirement.may
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.
Still, this suggests that an array to represents Levels and States is better
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.
That's not the point of this PR, isn't?
Co-authored-by: Pierangelo Di Pilato <pierangelodipilato@gmail.com>
This Pull Request is stale because it has been open for 90 days with |
Changes
/kind bug
Fixes #268
Release Note