Skip to content

Commit f4ef2eb

Browse files
committed
Add a func to generate a slice of CRD pointers from a slice of CRDs
1 parent ac8a924 commit f4ef2eb

File tree

4 files changed

+57
-0
lines changed

4 files changed

+57
-0
lines changed

envtestutils/envtestutils.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package envtestutils
2+
3+
import apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
4+
5+
// CRDPtrsFromCRDs generates a slice of CRD pointers from a slice of CRDs
6+
func CRDPtrsFromCRDs(crds []apiextensionsv1.CustomResourceDefinition) (ptrs []*apiextensionsv1.CustomResourceDefinition) {
7+
for i := range crds {
8+
ptrs = append(ptrs, &crds[i])
9+
}
10+
return
11+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright 2021 OnMetal authors
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package envtestutils
16+
17+
import (
18+
"testing"
19+
20+
. "github.com/onsi/ginkgo"
21+
. "github.com/onsi/gomega"
22+
)
23+
24+
func TestEnvtestutils(t *testing.T) {
25+
RegisterFailHandler(Fail)
26+
RunSpecs(t, "Envtestutils Suite")
27+
}

envtestutils/envtestutils_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package envtestutils
2+
3+
import (
4+
. "github.com/onsi/ginkgo"
5+
. "github.com/onsi/gomega"
6+
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
7+
)
8+
9+
var _ = Describe("CRDPtrsFromCRDs", func() {
10+
It("returns CRD pointers from CRDs", func() {
11+
crdA := apiextensionsv1.CustomResourceDefinition{}
12+
crdB := apiextensionsv1.CustomResourceDefinition{}
13+
14+
crds := []apiextensionsv1.CustomResourceDefinition{crdA, crdB}
15+
16+
Expect(CRDPtrsFromCRDs(crds)).To(Equal([]*apiextensionsv1.CustomResourceDefinition{&crdA, &crdB}))
17+
})
18+
})

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ require (
99
github.com/onsi/gomega v1.17.0
1010
github.com/spf13/pflag v1.0.5
1111
k8s.io/api v0.23.1
12+
k8s.io/apiextensions-apiserver v0.23.0
1213
k8s.io/apimachinery v0.23.1
1314
k8s.io/client-go v0.23.1
1415
sigs.k8s.io/controller-runtime v0.11.0

0 commit comments

Comments
 (0)