Skip to content

Commit 3a2f680

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 3a2f680

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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+
exec cue get go --local ./...
6+
cmp ./file2_go_gen.cue ./file2_go_gen.cue.golden
7+
8+
-- go.mod --
9+
module mod.test
10+
11+
go 1.21
12+
-- cue.mod/module.cue --
13+
module: "mod.test"
14+
-- file1.go --
15+
package pkg1
16+
17+
// +k8s:openapi-gen=true
18+
-- file2.go --
19+
package pkg1
20+
21+
type Foo struct {
22+
Required string `json:"required"`
23+
Pointer *string `json:"pointer"`
24+
OmitEmptyPointer *string `json:"omitEmptyPointer,omitempty"`
25+
// +optional
26+
OptionalComment string `json:"optionalComment"`
27+
// +optional
28+
OptionalCommentPointer *string `json:"optionalCommentPointer"`
29+
// +nullable
30+
NullableCommentPointer *string `json:"nullableCommentPointer"`
31+
}
32+
-- file2_go_gen.cue.golden --
33+
// Code generated by cue get go. DO NOT EDIT.
34+
35+
//cue:generate cue get go mod.test
36+
37+
package pkg1
38+
39+
#Foo: {
40+
required: string @go(Required)
41+
pointer?: null | string @go(Pointer,*string)
42+
omitEmptyPointer?: null | string @go(OmitEmptyPointer,*string)
43+
44+
// +optional
45+
optionalComment?: string @go(OptionalComment)
46+
47+
// +optional
48+
optionalCommentPointer?: null | string @go(OptionalCommentPointer,*string)
49+
50+
// +nullable
51+
nullableCommentPointer?: null | string @go(NullableCommentPointer,*string)
52+
}

0 commit comments

Comments
 (0)