Skip to content
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

Conversation

CaoShuFeng
Copy link
Contributor

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

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Aug 17, 2017
@k8s-github-robot k8s-github-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. release-note-none Denotes a PR that doesn't merit a release note. labels Aug 17, 2017
@CaoShuFeng CaoShuFeng force-pushed the remove_versioned_test_from_filters branch from f78525f to f88cc75 Compare August 17, 2017 12:53
SourceIPs: []string{
"127.0.0.1",
},
// Uncomment the next line this test would fail:
Copy link
Contributor Author

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.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

time.Truncate?

Copy link
Contributor Author

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.

@liggitt
Copy link
Member

liggitt commented Aug 17, 2017

/unassign

@CaoShuFeng
Copy link
Contributor Author

/test pull-kubernetes-e2e-gce-etcd3

Copy link

@crassirostris crassirostris left a 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))

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

Copy link
Contributor Author

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.

Copy link
Contributor Author

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)

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

Copy link
Contributor Author

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.

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?

Copy link
Contributor Author

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?

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:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

time.Truncate?

@CaoShuFeng CaoShuFeng force-pushed the remove_versioned_test_from_filters branch from f88cc75 to 987b28c Compare August 20, 2017 02:48
@CaoShuFeng
Copy link
Contributor Author

/test pull-kubernetes-kubemark-e2e-gce

2 similar comments
@CaoShuFeng
Copy link
Contributor Author

/test pull-kubernetes-kubemark-e2e-gce

@CaoShuFeng
Copy link
Contributor Author

/test pull-kubernetes-kubemark-e2e-gce

@CaoShuFeng CaoShuFeng closed this Aug 20, 2017
@CaoShuFeng CaoShuFeng reopened this Aug 20, 2017
@CaoShuFeng
Copy link
Contributor Author

/test pull-kubernetes-kubemark-e2e-gce

@CaoShuFeng
Copy link
Contributor Author

/test pull-kubernetes-kubemark-e2e-gce
/test pull-kubernetes-e2e-gce-etcd3

}
if (event.ResponseStatus == nil) != (expect.ResponseStatus == nil) {
t.Errorf("Unexpected ResponseStatus: %v", event.ResponseStatus)
continue
Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

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

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 :)

@crassirostris
Copy link

/retest

@CaoShuFeng
Copy link
Contributor Author

/test pull-kubernetes-kubemark-e2e-gce

@soltysh
Copy link
Contributor

soltysh commented Sep 1, 2017

/test pull-kubernetes-bazel-build
/test pull-kubernetes-bazel-test

@soltysh soltysh added this to the v1.8 milestone Sep 1, 2017
@k8s-github-robot k8s-github-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 1, 2017
@calebamiles calebamiles modified the milestone: v1.8 Sep 2, 2017
@CaoShuFeng CaoShuFeng force-pushed the remove_versioned_test_from_filters branch from 987b28c to d85132b Compare September 4, 2017 11:54
@k8s-github-robot k8s-github-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 4, 2017
@CaoShuFeng CaoShuFeng force-pushed the remove_versioned_test_from_filters branch 2 times, most recently from cb4da9f to 0f35dcd Compare September 4, 2017 12:50
@CaoShuFeng
Copy link
Contributor Author

/test pull-kubernetes-e2e-gce-etcd3

@soltysh
Copy link
Contributor

soltysh commented Sep 4, 2017

@calebmiles why did you remove the milestone from here, this is improving the test so it falls under the category of bugfixes/stabilization imo

@sttts sttts added the kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. label Sep 4, 2017
@CaoShuFeng
Copy link
Contributor Author

@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.
s/calebmiles/calebamiles
@calebamiles

@soltysh
Copy link
Contributor

soltysh commented Sep 6, 2017

@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

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Sep 6, 2017
@soltysh soltysh added this to the v1.8 milestone Sep 6, 2017
@CaoShuFeng CaoShuFeng force-pushed the remove_versioned_test_from_filters branch from 0f35dcd to 23d37fb Compare September 6, 2017 13:08
@k8s-github-robot k8s-github-robot added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed lgtm "Looks good to me", indicates that a PR is ready to be merged. labels Sep 6, 2017
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
@CaoShuFeng CaoShuFeng force-pushed the remove_versioned_test_from_filters branch from 23d37fb to c030026 Compare September 6, 2017 13:32
@k8s-github-robot k8s-github-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 6, 2017
@soltysh
Copy link
Contributor

soltysh commented Sep 6, 2017

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Sep 6, 2017
@soltysh
Copy link
Contributor

soltysh commented Sep 6, 2017

@sttts for approval

@sttts
Copy link
Contributor

sttts commented Sep 6, 2017

/approve no-issue

@k8s-github-robot
Copy link

[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 /approve in a comment
You can cancel your approval by writing /approve cancel in a comment

@k8s-github-robot k8s-github-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 6, 2017
@k8s-github-robot
Copy link

Automatic merge from submit-queue (batch tested with PRs 49133, 51557, 51749, 50842, 52018)

k8s-github-robot pushed a commit that referenced this pull request Sep 6, 2017
…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
```
@k8s-github-robot k8s-github-robot merged commit d369160 into kubernetes:master Sep 6, 2017
@CaoShuFeng CaoShuFeng deleted the remove_versioned_test_from_filters branch November 6, 2017 05:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/audit cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. lgtm "Looks good to me", indicates that a PR is ready to be merged. release-note-none Denotes a PR that doesn't merit a release note. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants