forked from kubernetes/kubernetes
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
606a9a0
commit 9b0f6b9
Showing
8 changed files
with
790 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
206 changes: 206 additions & 0 deletions
206
staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maxitems/doc.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,206 @@ | ||
/* | ||
Copyright 2024 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
// +k8s:validation-gen=TypeMeta | ||
// +k8s:validation-gen-scheme-registry=k8s.io/code-generator/cmd/validation-gen/testscheme.Scheme | ||
|
||
// This is a test package. | ||
package maxitems | ||
|
||
import "k8s.io/code-generator/cmd/validation-gen/testscheme" | ||
|
||
var localSchemeBuilder = testscheme.New() | ||
|
||
// Maxitems | ||
type M struct { | ||
TypeMeta int | ||
|
||
// slice-of-primitive | ||
// +k8s:validation:maxItems=1 | ||
M0 []int `json:"m0"` | ||
|
||
// typedef-of-slice-of-primitive | ||
// Validation on type only. | ||
M1 IntSliceLimited `json:"m1"` | ||
// Validation on field only. | ||
// +k8s:validation:maxItems=1 | ||
M2 IntSlice `json:"m2"` | ||
// Validation on both type and field. | ||
// +k8s:validation:maxItems=2 | ||
M3 IntSliceLimited `json:"m3"` | ||
|
||
// pointers to slice-of-primitive | ||
// Validation on field only. | ||
|
||
// +k8s:validation:maxItems=1 | ||
M4 *[]int `json:"m4"` | ||
|
||
// pointers to typedef-of-slice-of-primitive | ||
// Validation on type only | ||
M5 *IntSliceLimited `json:"m5"` | ||
// Validation on field only. | ||
// +k8s:validation:maxItems=1 | ||
M6 *IntSlice `json:"m6"` | ||
// Validation on both type and field. | ||
// +k8s:validation:maxItems=1 | ||
M7 *IntSliceLimited `json:"m7"` | ||
|
||
// slice-of-pointer-to-primitive | ||
// Validation on field only. | ||
// +k8s:validation:maxItems=1 | ||
M8 []*int `json:"m8"` | ||
|
||
// typedef-of-slice-of-pointer-to-primitive | ||
// Validation on type only. | ||
M9 IntPtrSliceLimited `json:"m9"` | ||
// Validation on field only. | ||
// +k8s:validation:maxItems=1 | ||
M10 IntPtrSlice `json:"m10"` | ||
// Validation on both type and field. | ||
// +k8s:validation:maxItems=1 | ||
M11 IntPtrSliceLimited `json:"m11"` | ||
|
||
// pointers to slice-of-pointer-to-primitive | ||
// Validation on field only. | ||
// +k8s:validation:maxItems=1 | ||
M12 *[]*int `json:"m12"` | ||
|
||
// pointers to typedef-of-slice-of-pointer-to-primitive | ||
// Validation on type only. | ||
M13 *IntPtrSliceLimited `json:"m13"` | ||
// Validation on field only. | ||
// +k8s:validation:maxItems=1 | ||
M14 *IntPtrSlice `json:"m14"` | ||
// Validation on both type and field. | ||
// +k8s:validation:maxItems=1 | ||
M15 *IntPtrSliceLimited `json:"m15"` | ||
|
||
// slice-of-struct | ||
// +k8s:validation:maxItems=1 | ||
M16 []S `json:"m16"` | ||
|
||
// typedef-of-slice-of-struct | ||
// Validation on type only. | ||
M17 SSliceLimited `json:"m17"` | ||
// Validation on field only. | ||
// +k8s:validation:maxItems=1 | ||
M18 SSlice `json:"m18"` | ||
// Validation on both type and field. | ||
// +k8s:validation:maxItems=1 | ||
M19 SSliceLimited `json:"m19"` | ||
|
||
// pointers to slice-of-struct | ||
// Validation on type only. | ||
M20 *[]SSliceLimited `json:"m20"` | ||
// Validation on field only. | ||
// +k8s:validation:maxItems=1 | ||
M21 *[]SSlice `json:"m21"` | ||
// Validation on both type and field. | ||
// +k8s:validation:maxItems=1 | ||
M22 *[]SSliceLimited `json:"m22"` | ||
|
||
// pointers to typedef-of-slice-of-struct | ||
// Validation on type only. | ||
M23 *SSliceLimited `json:"m23"` | ||
// Validation on field only. | ||
// +k8s:validation:maxItems=1 | ||
M24 *SSlice `json:"m24"` | ||
// Validation on both type and field. | ||
// +k8s:validation:maxItems=1 | ||
M25 *SSliceLimited `json:"m25"` | ||
|
||
// slice-of-pointer-to-struct | ||
// +k8s:validation:maxItems=1 | ||
M26 []*S `json:"m26"` | ||
|
||
// typedef-of-slice-of-pointer-to-struct | ||
// Validation on type only. | ||
M27 SPtrSliceLimited `json:"m27"` | ||
// Validation on field only. | ||
// +k8s:validation:maxItems=1 | ||
M28 SPtrSlice `json:"m28"` | ||
// Validation on both type and field. | ||
// +k8s:validation:maxItems=1 | ||
M29 SPtrSliceLimited `json:"m29"` | ||
|
||
// pointers to slice-of-pointer-to-struct | ||
// +k8s:validation:maxItems=1 | ||
M30 *[]*S `json:"m30"` | ||
|
||
// pointers to typedef-of-slice-of-pointer-to-struct | ||
// Validation on type only. | ||
M31 *SPtrSliceLimited `json:"m31"` | ||
// Validation on field only. | ||
// +k8s:validation:maxItems=1 | ||
M32 *SPtrSlice `json:"m32"` | ||
// Validation on both type and field. | ||
// +k8s:validation:maxItems=1 | ||
M33 *SPtrSliceLimited `json:"m33"` | ||
|
||
// slice-of-slice-of-value | ||
// +k8s:validation:maxItems=1 | ||
M34 [][]int `json:"m34"` | ||
|
||
// slice-of-typedef-of-slice-of-value | ||
// Validation on type only. | ||
M36 []IntSliceLimited `json:"m36"` | ||
// Validation on field only. | ||
// +k8s:validation:maxItems=1 | ||
M35 []IntSlice `json:"m35"` | ||
// Validation on both type and field. | ||
// +k8s:validation:maxItems=1 | ||
M37 []IntSliceLimited `json:"m37"` | ||
|
||
// slice-of-slice-of-pointer | ||
// +k8s:validation:maxItems=1 | ||
M38 [][]*int `json:"m38"` | ||
|
||
// slice-of-typedef-of-slice-of-pointer | ||
// Validation on field only. | ||
// +k8s:validation:maxItems=1 | ||
M39 []IntPtrSlice `json:"m39"` | ||
// Validation on type only. | ||
M40 []IntPtrSliceLimited `json:"m40"` | ||
// Validation on both type and field. | ||
// +k8s:validation:maxItems=1 | ||
M41 []IntPtrSliceLimited `json:"m41"` | ||
} | ||
|
||
// Note: no limit here | ||
type IntSlice []int | ||
|
||
// +k8s:validation:maxItems=2 | ||
type IntSliceLimited []int | ||
|
||
// Note: no limit here | ||
type IntPtrSlice []*int | ||
|
||
// +k8s:validation:maxItems=2 | ||
type IntPtrSliceLimited []*int | ||
|
||
type S struct{} | ||
|
||
// Note: no limit here | ||
type SSlice []S | ||
|
||
// +k8s:validation:maxItems=2 | ||
type SSliceLimited []S | ||
|
||
// +k8s:validation:maxItems=2 | ||
type SPtrSliceLimited []*S | ||
|
||
// Note: no limit here | ||
type SPtrSlice []*S |
29 changes: 29 additions & 0 deletions
29
staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maxitems/docs_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
Copyright 2024 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package maxitems | ||
|
||
import ( | ||
"testing" | ||
// "k8s.io/apimachinery/pkg/util/validation/field" | ||
) | ||
|
||
func Test(t *testing.T) { | ||
st := localSchemeBuilder.Test(t) | ||
|
||
// Testing M0 | ||
st.Value(&M{M0: []int{1}, M4: &[]int{1}}).ExpectValid() | ||
} |
Oops, something went wrong.