-
Notifications
You must be signed in to change notification settings - Fork 38.6k
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
enhance unit tests of advance audit feature #50842
enhance unit tests of advance audit feature #50842
Conversation
f78525f
to
f88cc75
Compare
SourceIPs: []string{ | ||
"127.0.0.1", | ||
}, | ||
// Uncomment the next line this test would fail: |
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.
Please take a look at here.
I think this is OK, and it's not an issue for me.
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.
time.Truncate?
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.
Yeap, time.Truncate runs happliy.
/unassign |
/test pull-kubernetes-e2e-gce-etcd3 |
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.
LGTM, couple of nits
if len(line) != len(test.expected) { | ||
t.Errorf("[%s] Unexpected amount of lines in audit log: %d", test.desc, len(line)) | ||
if len(events) != len(test.expected) { | ||
t.Errorf("[%s] Unexpected amount of lines in audit log: %d", test.desc, len(events)) |
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.
If this is Errorf, the execution will continue and line event := events[i]
can panic with index out of range
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.
There is a "continue" in the next line.
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.
After using t.Run(), "continue" can't be used.
Changed to t.Fatal().
resp := w.Result() | ||
if test.expectedHeader { | ||
if resp.Header.Get("Audit-ID") == "" { | ||
t.Errorf("[%s] expected Audit-ID http header returned, but not returned", test.desc) |
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.
Instead of putting [%s] in front of each string, you can use the following approach:
for _, tc := range tcs {
t.Run(tc.desc, func() {
...
})
}
Then you can use t.Failf
to fail the test without continuation
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.
Then you can use t.Failf to fail the test without continuation
Done.
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.
@CaoShuFeng Haven't pushed the changes?
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.
@CaoShuFeng Haven't pushed the changes?
I mean this is done in line 621.
I other places, we can use t.Errorf() to continue the tests to get more error messages. What do you think?
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.
But this particular place has continue
afterwards :)
Anyway, if there's no kubernetes-wide policy about tests, do as you wish, that's just my feeling that writing t.Run once is better than writing it in each log line, at least for new tests.
SourceIPs: []string{ | ||
"127.0.0.1", | ||
}, | ||
// Uncomment the next line this test would fail: |
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.
time.Truncate?
f88cc75
to
987b28c
Compare
/test pull-kubernetes-kubemark-e2e-gce |
2 similar comments
/test pull-kubernetes-kubemark-e2e-gce |
/test pull-kubernetes-kubemark-e2e-gce |
/test pull-kubernetes-kubemark-e2e-gce |
/test pull-kubernetes-kubemark-e2e-gce |
} | ||
if (event.ResponseStatus == nil) != (expect.ResponseStatus == nil) { | ||
t.Errorf("Unexpected ResponseStatus: %v", event.ResponseStatus) | ||
continue |
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.
But this particular place has continue afterwards :)
Do you mean the continue
in this line?
I think the continue
here is OK.
For example, there are 3 events in test.expected totally. And it fails in line 646 for the first event, so we run continue
. And the check in line 650 is skipped, and then we will check the next 2 events.
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.
If we use t.Fatalf(), we will not check other events after the first fatal.
That's my opinion.
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.
Ah, sure, agree, it's fine here, sorry :)
} | ||
if (event.ResponseStatus == nil) != (expect.ResponseStatus == nil) { | ||
t.Errorf("Unexpected ResponseStatus: %v", event.ResponseStatus) | ||
continue |
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.
Ah, sure, agree, it's fine here, sorry :)
/retest |
/test pull-kubernetes-kubemark-e2e-gce |
/test pull-kubernetes-bazel-build |
987b28c
to
d85132b
Compare
cb4da9f
to
0f35dcd
Compare
/test pull-kubernetes-e2e-gce-etcd3 |
@calebmiles why did you remove the milestone from here, this is improving the test so it falls under the category of bugfixes/stabilization imo |
Another people is pinged. |
@jdumars I'm adding a 1.8 milestone back here, since this is fixing tests/improving stability of the code. The only reason it wasn't approved and lgtm-ed on Fri is it needed a rebase. /lgtm |
0f35dcd
to
23d37fb
Compare
This change does three things: 1. use auditinternal for unit test in filter stage 2. add a seperate unit test for Audit-ID http header 3. add unit test for audit log backend
23d37fb
to
c030026
Compare
/lgtm |
@sttts for approval |
/approve no-issue |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: CaoShuFeng, soltysh, sttts Associated issue requirement bypassed by: sttts The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these OWNERS Files:
You can indicate your approval by writing |
Automatic merge from submit-queue (batch tested with PRs 49133, 51557, 51749, 50842, 52018) |
…filters Automatic merge from submit-queue (batch tested with PRs 49133, 51557, 51749, 50842, 52018) enhance unit tests of advance audit feature This change addresses comments from @crassirostris #49115 (comment) It does three things: 1. use auditinternal for unit test in filter stage 2. add a seperate unit test for Audit-ID http header 3. add unit test for audit log backend **Release note**: ``` NONE ```
This change addresses comments from @crassirostris
#49115 (comment)
It does three things:
Release note: