Skip to content

Commit 9821d0e

Browse files
authored
Merge pull request kubernetes#88486 from Jefftree/schnake-pr
Adds custom reporter and logic to generate conformance docs and list of tests
2 parents 1f11cac + 2683b10 commit 9821d0e

File tree

14 files changed

+3053
-729
lines changed

14 files changed

+3053
-729
lines changed

test/conformance/BUILD

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,16 @@ load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library", "go_test")
22

33
go_library(
44
name = "go_default_library",
5-
srcs = ["walk.go"],
5+
srcs = [
6+
"doc.go",
7+
"walk.go",
8+
],
69
importpath = "k8s.io/kubernetes/test/conformance",
710
visibility = ["//visibility:private"],
11+
deps = [
12+
"//vendor/github.com/onsi/ginkgo/types:go_default_library",
13+
"//vendor/gopkg.in/yaml.v2:go_default_library",
14+
],
815
)
916

1017
go_binary(
@@ -32,22 +39,35 @@ filegroup(
3239
)
3340

3441
genrule(
35-
name = "list_conformance_tests",
42+
name = "list_conformance_specs",
3643
srcs = [
3744
"//test/e2e:all-srcs",
3845
"//test/e2e_node:all-srcs",
46+
"//test/e2e:e2e.test_binary",
47+
"//vendor/github.com/onsi/ginkgo/ginkgo",
3948
],
40-
outs = ["conformance.txt"],
41-
cmd = "./$(location :conformance) $(locations //test/e2e:all-srcs) > $@",
49+
outs = ["specsummaries.json"],
50+
cmd = "$(location //vendor/github.com/onsi/ginkgo/ginkgo) --dryRun=true --focus=[Conformance] $(location //test/e2e:e2e.test_binary) -- --spec-dump $$(pwd)/$@ > /dev/null",
51+
message = "Getting all conformance spec summaries.",
52+
)
53+
54+
genrule(
55+
name = "list_conformance_tests",
56+
srcs = [
57+
":list_conformance_specs",
58+
":conformance",
59+
"//test/e2e:all-srcs",
60+
],
61+
outs = ["conformance.yaml"],
62+
cmd = "$(location :conformance) $(location :list_conformance_specs) > $@",
4263
message = "Listing all conformance tests.",
43-
tools = [":conformance"],
4464
)
4565

4666
sh_test(
4767
name = "conformance_test",
4868
srcs = ["conformance_test.sh"],
4969
data = [
50-
"testdata/conformance.txt",
70+
"testdata/conformance.yaml",
5171
":list_conformance_tests",
5272
],
5373
)
@@ -58,3 +78,16 @@ go_test(
5878
data = glob(["testdata/**"]),
5979
embed = [":go_default_library"],
6080
)
81+
82+
genrule(
83+
name = "gen_conformance_docs",
84+
srcs = [
85+
":list_conformance_specs",
86+
":conformance",
87+
"//test/e2e:all-srcs",
88+
":package-srcs",
89+
],
90+
outs = ["conformance.md"],
91+
cmd = "$(location :conformance) --docs $(location :list_conformance_specs) > $@",
92+
message = "Listing all conformance tests.",
93+
)

test/conformance/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ To update the list, run
99

1010
```console
1111
bazel build //test/conformance:list_conformance_tests
12-
cp bazel-genfiles/test/conformance/conformance.txt test/conformance/testdata
12+
cp bazel-genfiles/test/conformance/conformance.yaml test/conformance/testdata
1313
```
1414

1515
Add the changed file to your PR, then send for review.

test/conformance/cf_header.md

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,24 @@ clean up the tests.
1515
Example:
1616
```
1717
/*
18-
Testname: Kubelet-OutputToLogs
19-
Release: v1.9
20-
Description: By default the stdout and stderr from the process
21-
being executed in a pod MUST be sent to the pod's logs.
18+
Release : v1.13
19+
Testname: Kubelet, log output, default
20+
Description: By default the stdout and stderr from the process being executed in a pod MUST be sent to the pod's logs.
2221
*/
23-
// Note this test needs to be fixed to also test for stderr
24-
It("it should print the output to logs [Conformance]", func() {
22+
framework.ConformanceIt("should print the output to logs [NodeConformance]", func() {
2523
```
2624

2725
would generate the following documentation for the test. Note that the "TestName" from the Documentation above will
2826
be used to document the test which make it more human readable. The "Description" field will be used as the
2927
documentation for that test.
3028

3129
### **Output:**
32-
## [Kubelet-OutputToLogs](https://github.com/kubernetes/kubernetes/blob/release-1.9/test/e2e_node/kubelet_test.go#L42)
30+
## [Kubelet, log output, default](https://github.com/kubernetes/kubernetes/tree/master/test/e2e/common/kubelet.go#L48)
3331

34-
### Release v1.9
35-
By default the stdout and stderr from the process
36-
being executed in a pod MUST be sent to the pod's logs.
37-
Note this test needs to be fixed to also test for stderr
32+
- Added to conformance in release v1.13
33+
- Defined in code as: [k8s.io] Kubelet when scheduling a busybox command in a pod should print the output to logs [NodeConformance] [Conformance]
34+
35+
By default the stdout and stderr from the process being executed in a pod MUST be sent to the pod's logs.
3836

3937
Notational Conventions when documenting the tests with the key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" are to be interpreted as described in [RFC 2119](https://tools.ietf.org/html/rfc2119).
4038

test/conformance/conformance_test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
set -o errexit
2323

24-
if diff -u test/conformance/testdata/conformance.txt test/conformance/conformance.txt; then
24+
if diff -u test/conformance/testdata/conformance.yaml test/conformance/conformance.yaml; then
2525
echo PASS
2626
exit 0
2727
fi

test/conformance/doc.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
Copyright 2019 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
/*
18+
This stand-alone package is utilized for dynamically generating/maintaining a list of
19+
conformance tests. It utilizes a two step approach:
20+
- The test binary is built
21+
- The test binary is run in dry mode with a custom ginkgo reporter dumping out
22+
types.SpecSummary objects which contain full test names and file/code information.
23+
- The SpecSummary information is parsed to get file/line info on Conformance tests and
24+
then we use a simplified AST parser to grab the comments above the test.
25+
26+
Due to the complicated nature of how tests can be declared/wrapped in various contexts,
27+
this approach is much simpler to maintain than a pure-AST parser and allows us to easily
28+
capture the full test names/locations of the tests using the pre-existing ginkgo logic.
29+
*/
30+
package main

0 commit comments

Comments
 (0)