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
94c0da1
commit 966d387
Showing
5 changed files
with
231 additions
and
0 deletions.
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
46 changes: 46 additions & 0 deletions
46
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,46 @@ | ||
/* | ||
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 | ||
|
||
// +k8s:validation:maxItems=3 | ||
M1 LT `json:"m1"` | ||
|
||
// +k8s:validation:maxItems=1 | ||
M2 LT `json:"m2"` | ||
|
||
// +k8s:validation:maxItems=1 | ||
M3 []T `json:"m3"` | ||
|
||
M4 LT `json:"m4"` | ||
} | ||
|
||
// +k8s:validation:maxItems=2 | ||
type LT []T | ||
|
||
type T struct{} |
54 changes: 54 additions & 0 deletions
54
staging/src/k8s.io/code-generator/cmd/validation-gen/output_tests/maxitems/doc_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,54 @@ | ||
/* | ||
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 M1 | ||
st.Value(&M{M1: []T{{}, {}}}).ExpectValid() | ||
st.Value(&M{M1: []T{{}, {}, {}}}).ExpectInvalid( | ||
field.TooMany(field.NewPath("m1"), 3, 2), | ||
) | ||
st.Value(&M{M1: []T{{}, {}, {}}}).ExpectInvalid( | ||
field.TooMany(field.NewPath("m1"), 3, 2), | ||
) | ||
|
||
// Testing M2 | ||
st.Value(&M{M2: []T{{}}}).ExpectValid() | ||
st.Value(&M{M2: []T{{}, {}, {}, {}}}).ExpectInvalid( | ||
field.TooMany(field.NewPath("m2"), 4, 1), | ||
) | ||
|
||
// Testing M3 | ||
st.Value(&M{M3: []T{{}}}).ExpectValid() | ||
st.Value(&M{M3: []T{{}, {}}}).ExpectInvalid( | ||
field.TooMany(field.NewPath("m3"), 2, 1), | ||
) | ||
|
||
// Testing M4 | ||
st.Value(&M{M4: []T{{}, {}}}).ExpectValid() | ||
st.Value(&M{M4: []T{{}, {}, {}}}).ExpectInvalid( | ||
field.TooMany(field.NewPath("m4"), 3, 2), | ||
) | ||
} |
101 changes: 101 additions & 0 deletions
101
...8s.io/code-generator/cmd/validation-gen/output_tests/maxitems/zz_generated.validations.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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