Skip to content

Commit b5f9a00

Browse files
jpbetzthockinaaron-prindleyongruilin
committed
Add validation-gen core tests
Co-authored-by: Tim Hockin <[email protected]> Co-authored-by: Aaron Prindle <[email protected]> Co-authored-by: Yongrui Lin <[email protected]>
1 parent 8c41bdf commit b5f9a00

File tree

225 files changed

+14178
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

225 files changed

+14178
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
Copyright 2024 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+
// +k8s:validation-gen=*
18+
19+
// This is a test package. It exists to demonstrate references to types that
20+
// are not part of the gengo args. Even though this package purports to have
21+
// validations, it is outside of the args used when generating output_tests,
22+
// and so the generated could should NOT descend into these.
23+
package other
24+
25+
// +k8s:validateFalse="you should not see this outside of this pkg"
26+
type StringType string
27+
28+
// +k8s:validateFalse="you should not see this outside of this pkg"
29+
type IntType int
30+
31+
// +k8s:validateFalse="you should not see this outside of this pkg"
32+
type StructType struct {
33+
// +k8s:validateFalse="you should not see this outside of this pkg"
34+
StringField string `json:"stringField"`
35+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
Copyright 2024 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+
// Note: this selects all types in the package.
18+
// +k8s:validation-gen=*
19+
// +k8s:validation-gen-scheme-registry=k8s.io/code-generator/cmd/validation-gen/testscheme.Scheme
20+
// +k8s:validation-gen-test-fixture=validateFalse
21+
22+
// This is a test package.
23+
package trivial
24+
25+
import "k8s.io/code-generator/cmd/validation-gen/testscheme"
26+
27+
var localSchemeBuilder = testscheme.New()
28+
29+
type T1 struct{}
30+
31+
type T2 struct{}
32+
33+
type E1 string
34+
35+
type E2 string
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/all_types_match/trivial/zz_generated.validations.go

Lines changed: 34 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/all_types_match/trivial/zz_generated.validations_test.go

Lines changed: 30 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
Copyright 2024 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+
// Note: this selects all types in the package.
18+
// +k8s:validation-gen=*
19+
// +k8s:validation-gen-scheme-registry=k8s.io/code-generator/cmd/validation-gen/testscheme.Scheme
20+
// +k8s:validation-gen-test-fixture=validateFalse
21+
22+
// This is a test package.
23+
package withfieldvalidations
24+
25+
import "k8s.io/code-generator/cmd/validation-gen/testscheme"
26+
27+
var localSchemeBuilder = testscheme.New()
28+
29+
type T1 struct {
30+
// +k8s:validateFalse="field T1.S"
31+
S string `json:"s"`
32+
// +k8s:validateFalse="field T1.T2"
33+
T2 T2 `json:"t2"`
34+
// +k8s:validateFalse="field T1.T3"
35+
T3 T3 `json:"t3"`
36+
}
37+
38+
// Note: this has validations and is linked into T1.
39+
type T2 struct {
40+
// +k8s:validateFalse="field T2.S"
41+
S string `json:"s"`
42+
}
43+
44+
// Note: this has no validations and is linked into T1.
45+
type T3 struct {
46+
S string `json:"s"`
47+
}
48+
49+
// Note: this has validations and is not linked into T1.
50+
type T4 struct {
51+
// +k8s:validateFalse="field T4.S"
52+
S string `json:"s"`
53+
}
54+
55+
// Note: this has no validations and is not linked into T1.
56+
type T5 struct {
57+
S string `json:"s"`
58+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"*withfieldvalidations.T1": {
3+
"s": [
4+
"field T1.S"
5+
],
6+
"t2": [
7+
"field T1.T2"
8+
],
9+
"t2.s": [
10+
"field T2.S"
11+
],
12+
"t3": [
13+
"field T1.T3"
14+
]
15+
},
16+
"*withfieldvalidations.T2": {
17+
"s": [
18+
"field T2.S"
19+
]
20+
},
21+
"*withfieldvalidations.T4": {
22+
"s": [
23+
"field T4.S"
24+
]
25+
}
26+
}

staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/all_types_match/with_field_validations/zz_generated.validations.go

Lines changed: 107 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/all_types_match/with_field_validations/zz_generated.validations_test.go

Lines changed: 30 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)