Skip to content

Commit 12e5493

Browse files
committed
cmd/cue: add kubernetes semantics test
We are currently generating "wrong" schemas from K8s source when comparing against their OpenAPI spec. Change-Id: Ieb30f98ba2bdc921ab48c81aedbdc89c685b4bd9 Signed-off-by: Tim Windelschmidt <[email protected]>
1 parent 4d54b90 commit 12e5493

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Test that a get go works for kubernetes types,
2+
# including those special cases that result in _ and string
3+
# that are specifically mentioned in help get go.
4+
5+
# cue get go
6+
exec cue get go --local ./...
7+
cmp ./file2_go_gen.cue ./file2_go_gen.cue.golden
8+
9+
-- go.mod --
10+
module mod.test
11+
12+
go 1.21
13+
-- cue.mod/module.cue --
14+
module: "mod.test"
15+
-- file1.go --
16+
package pkg1
17+
18+
// +k8s:openapi-gen=true
19+
-- file2.go --
20+
package pkg1
21+
22+
type Foo struct {
23+
Required string `json:"required"`
24+
Pointer *string `json:"pointer"`
25+
OmitEmptyTagPointer *string `json:"omitEmptyTagPointer,omitempty"`
26+
// +optional
27+
OptionalCommentTagPointer *string `json:"optionalCommentTagPointer"`
28+
// +nullable
29+
NullableCommentTagPointer *string `json:"nullableCommentTagPointer"`
30+
}
31+
-- file2_go_gen.cue.golden --
32+
// Code generated by cue get go. DO NOT EDIT.
33+
34+
//cue:generate cue get go mod.test
35+
36+
package pkg1
37+
38+
#Foo: {
39+
required: string @go(Required)
40+
pointer?: null | string @go(Pointer,*string)
41+
omitEmptyTagPointer?: null | string @go(OmitEmptyTagPointer,*string)
42+
43+
// +optional
44+
optionalCommentTagPointer?: null | string @go(OptionalCommentTagPointer,*string)
45+
46+
// +nullable
47+
nullableCommentTagPointer?: null | string @go(NullableCommentTagPointer,*string)
48+
}

0 commit comments

Comments
 (0)