|
15 | 15 | package conditions |
16 | 16 |
|
17 | 17 | import ( |
18 | | - "fmt" |
19 | | - "os" |
20 | | - "os/exec" |
21 | | - "path/filepath" |
22 | 18 | "testing" |
23 | 19 |
|
24 | 20 | . "github.com/onsi/ginkgo" |
25 | 21 | . "github.com/onsi/gomega" |
26 | | - apiv1 "github.com/operator-framework/api/pkg/operators/v1" |
27 | | - "k8s.io/apimachinery/pkg/runtime" |
28 | | - "k8s.io/apimachinery/pkg/util/rand" |
29 | | - "k8s.io/client-go/rest" |
30 | | - "sigs.k8s.io/controller-runtime/pkg/envtest" |
| 22 | + |
31 | 23 | "sigs.k8s.io/controller-runtime/pkg/envtest/printer" |
32 | | - logf "sigs.k8s.io/controller-runtime/pkg/log" |
33 | | - "sigs.k8s.io/controller-runtime/pkg/log/zap" |
34 | 24 | ) |
35 | 25 |
|
36 | 26 | func TestSource(t *testing.T) { |
37 | 27 | RegisterFailHandler(Fail) |
38 | 28 | RunSpecsWithDefaultAndCustomReporters(t, "Conditions Suite", []Reporter{printer.NewlineReporter{}, printer.NewProwReporter("Conditions Suite")}) |
39 | 29 | } |
40 | | - |
41 | | -var testenv *envtest.Environment |
42 | | -var cfg *rest.Config |
43 | | -var sch = runtime.NewScheme() |
44 | | -var err error |
45 | | -var tempDir = fmt.Sprintf("%s_%d", "temp", rand.Int63nRange(0, 1000000)) |
46 | | - |
47 | | -const ( |
48 | | - olmYAMLURL = "https://github.com/operator-framework/operator-lifecycle-manager/releases/download/v0.17.0/olm.yaml" |
49 | | - crdsYAMLURL = "https://github.com/operator-framework/operator-lifecycle-manager/releases/download/v0.17.0/crds.yaml" |
50 | | - |
51 | | - // TODO: Remove this once OLM releases operator conditions CRD set |
52 | | - condCRDYAML = "https://raw.githubusercontent.com/dinhxuanvu/operator-lifecycle-manager/create-operatorconditions-for-operator/deploy/chart/crds/0000_50_olm_00-operatorconditions.crd.yaml" |
53 | | -) |
54 | | - |
55 | | -var _ = BeforeSuite(func(done Done) { |
56 | | - logf.SetLogger(zap.New(zap.WriteTo(GinkgoWriter), zap.UseDevMode(true))) |
57 | | - |
58 | | - err = getOLMManifests() |
59 | | - Expect(err).NotTo(HaveOccurred()) |
60 | | - // Add operator apiv1 to scheme |
61 | | - err = apiv1.AddToScheme(sch) |
62 | | - Expect(err).NotTo(HaveOccurred()) |
63 | | - |
64 | | - testenv = &envtest.Environment{} |
65 | | - testenv.CRDInstallOptions = envtest.CRDInstallOptions{ |
66 | | - Paths: []string{tempDir}, |
67 | | - } |
68 | | - |
69 | | - cfg, err = testenv.Start() |
70 | | - Expect(err).NotTo(HaveOccurred()) |
71 | | - |
72 | | - close(done) |
73 | | -}, 60) |
74 | | - |
75 | | -var _ = AfterSuite(func() { |
76 | | - // remove tmp folder |
77 | | - os.RemoveAll(tempDir) |
78 | | - Expect(err).NotTo(HaveOccurred()) |
79 | | - Expect(testenv.Stop()).To(Succeed()) |
80 | | -}) |
81 | | - |
82 | | -func getOLMManifests() error { |
83 | | - // create a directory |
84 | | - cmd := exec.Command("mkdir", tempDir) |
85 | | - err := cmd.Run() |
86 | | - if err != nil { |
87 | | - return err |
88 | | - } |
89 | | - |
90 | | - // fetch manifests to install olm |
91 | | - err = getYAML(filepath.Join(tempDir, "olm.yaml"), olmYAMLURL) |
92 | | - if err != nil { |
93 | | - return fmt.Errorf("error fetching olm.yaml %v", err) |
94 | | - } |
95 | | - |
96 | | - err = getYAML(filepath.Join(tempDir, "crds.yaml"), crdsYAMLURL) |
97 | | - if err != nil { |
98 | | - return fmt.Errorf("error fetching crds.yaml %v", err) |
99 | | - } |
100 | | - |
101 | | - err = getYAML(filepath.Join(tempDir, "operatorconditions.crd.yaml"), condCRDYAML) |
102 | | - if err != nil { |
103 | | - return fmt.Errorf("error fetching operator conditions crd %v", err) |
104 | | - } |
105 | | - return nil |
106 | | -} |
107 | | - |
108 | | -func getYAML(file, url string) error { |
109 | | - cmd := exec.Command("curl", "-sSLo", file, url) |
110 | | - err := cmd.Run() |
111 | | - if err != nil { |
112 | | - return err |
113 | | - } |
114 | | - return nil |
115 | | -} |
0 commit comments