-
Notifications
You must be signed in to change notification settings - Fork 48
/
e2e_suite_test.go
86 lines (71 loc) · 2.14 KB
/
e2e_suite_test.go
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
package e2e
import (
"context"
"os"
"testing"
"time"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/client-go/rest"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
catalogd "github.com/operator-framework/catalogd/api/core/v1alpha1"
"github.com/operator-framework/operator-controller/pkg/scheme"
)
var (
cfg *rest.Config
c client.Client
)
const (
testCatalogRefEnvVar = "CATALOG_IMG"
testCatalogName = "test-catalog"
latestImageTag = "latest"
)
func TestMain(m *testing.M) {
cfg = ctrl.GetConfigOrDie()
var err error
c, err = client.New(cfg, client.Options{Scheme: scheme.Scheme})
utilruntime.Must(err)
os.Exit(m.Run())
}
// createTestCatalog will create a new catalog on the test cluster, provided
// the context, catalog name, and the image reference. It returns the created catalog
// or an error if any errors occurred while creating the catalog.
func createTestCatalog(ctx context.Context, name string, imageRef string) (*catalogd.ClusterCatalog, error) {
catalog := &catalogd.ClusterCatalog{
ObjectMeta: metav1.ObjectMeta{
Name: name,
},
Spec: catalogd.ClusterCatalogSpec{
Source: catalogd.CatalogSource{
Type: catalogd.SourceTypeImage,
Image: &catalogd.ImageSource{
Ref: imageRef,
InsecureSkipTLSVerify: true,
PollInterval: &metav1.Duration{Duration: time.Second},
},
},
},
}
err := c.Create(ctx, catalog)
return catalog, err
}
// patchTestCatalog will patch the existing clusterCatalog on the test cluster, provided
// the context, catalog name, and the image reference. It returns an error
// if any errors occurred while updating the catalog.
func patchTestCatalog(ctx context.Context, name string, newImageRef string) error {
// Fetch the existing ClusterCatalog
catalog := &catalogd.ClusterCatalog{}
err := c.Get(ctx, client.ObjectKey{Name: name}, catalog)
if err != nil {
return err
}
// Update the ImageRef
catalog.Spec.Source.Image.Ref = newImageRef
// Patch the ClusterCatalog
err = c.Update(ctx, catalog)
if err != nil {
return err
}
return err
}