This repository was archived by the owner on Jun 24, 2026. It is now read-only.
forked from katanomi/pkg
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathoptions_test.go
More file actions
153 lines (129 loc) · 4.01 KB
/
Copy pathoptions_test.go
File metadata and controls
153 lines (129 loc) · 4.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
/*
Copyright 2023 The AlaudaDevops 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 client
import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
)
var _ = Describe("Test.GetOptions", func() {
var (
opts *GetOptions
)
BeforeEach(func() {
opts = NewGetOptions()
})
Describe("init", func() {
Context("when GetOptions is not nil and Raw is not nil", func() {
It("should return the input GetOptions", func() {
raw := &metav1.GetOptions{}
opt := &GetOptions{
GetOptions: client.GetOptions{
Raw: raw,
},
}
Expect(opt.init()).To(Equal(opt))
})
})
Context("when GetOptions is nil or Raw is nil", func() {
It("should return a new GetOptions with Raw set to a new instance of metav1.GetOptions", func() {
Expect(opts.init()).To(Equal(&GetOptions{
GetOptions: client.GetOptions{
Raw: &metav1.GetOptions{},
},
}))
})
})
})
Describe("WithCached", func() {
It("should set the ResourceVersion to '0'", func() {
Expect(opts.WithCached().Build().Raw.ResourceVersion).To(Equal("0"))
})
})
Describe("Build", func() {
It("should return a pointer to the underlying client.GetOptions", func() {
Expect(opts.Build()).To(BeIdenticalTo(&opts.GetOptions))
})
})
})
var _ = Describe("GetCachedOptions", func() {
It("should return client.GetOptions with ResourceVersion 0", func() {
options := GetCachedOptions()
Expect(options).ToNot(BeNil())
Expect(options.Raw).To(Equal(&metav1.GetOptions{ResourceVersion: "0"}))
})
})
var _ = Describe("Test.ListOptions", func() {
var (
opts *ListOptions
)
BeforeEach(func() {
opts = NewListOptions()
})
Describe("init", func() {
Context("when ListOptions is not nil and Raw is not nil", func() {
It("should return the input ListOptions", func() {
raw := &metav1.ListOptions{}
opt := &ListOptions{
ListOptions: client.ListOptions{
Raw: raw,
},
}
Expect(opt.init()).To(Equal(opt))
})
})
Context("when ListOptions is nil or Raw is nil", func() {
It("should return a new ListOptions with Raw set to a new instance of metav1.ListOptions", func() {
Expect(opts.init()).To(Equal(&ListOptions{
ListOptions: client.ListOptions{
Raw: &metav1.ListOptions{},
},
}))
})
})
})
Describe("WithCached", func() {
It("should set the ResourceVersion to '0'", func() {
Expect(opts.WithCached().Build().Raw.ResourceVersion).To(Equal("0"))
})
})
Describe("WithLimit", func() {
It("should set the Limit", func() {
Expect(opts.WithLimit(10).Build().Limit).To(Equal(int64(10)))
})
})
Describe("WithNamespace", func() {
It("should set the Namespace", func() {
Expect(opts.WithNamespace("NS").Build().Namespace).To(Equal("NS"))
})
})
Describe("WithUnsafeDisableDeepCopy", func() {
It("should set the UnsafeDisableDeepCopy to true", func() {
Expect(opts.WithUnsafeDisableDeepCopy().Build().UnsafeDisableDeepCopy).NotTo(BeNil())
Expect(*opts.WithUnsafeDisableDeepCopy().Build().UnsafeDisableDeepCopy).To(BeTrue())
})
})
Describe("Build", func() {
It("should return a pointer to the underlying client.ListOptions", func() {
Expect(opts.Build()).To(BeIdenticalTo(&opts.ListOptions))
})
})
})
var _ = Describe("ListCachedOptions", func() {
It("should return client.ListOptions with ResourceVersion 0", func() {
options := ListCachedOptions()
Expect(options).ToNot(BeNil())
Expect(options.Raw).To(Equal(&metav1.ListOptions{ResourceVersion: "0"}))
})
})