|
1 | 1 | package ownerutil
|
2 | 2 |
|
3 |
| -import "testing" |
| 3 | +import ( |
| 4 | + "testing" |
| 5 | + |
| 6 | + "github.com/stretchr/testify/assert" |
| 7 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 8 | + |
| 9 | + operatorsv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1" |
| 10 | +) |
4 | 11 |
|
5 | 12 | func TestIsOwnedBy(t *testing.T) {
|
6 | 13 | return
|
7 | 14 | }
|
| 15 | + |
| 16 | +func TestCSVOwnerSelector(t *testing.T) { |
| 17 | + csvType := metav1.TypeMeta{ |
| 18 | + Kind: operatorsv1alpha1.ClusterServiceVersionKind, |
| 19 | + APIVersion: operatorsv1alpha1.GroupVersion, |
| 20 | + } |
| 21 | + |
| 22 | + tests := []struct { |
| 23 | + name string |
| 24 | + csv *operatorsv1alpha1.ClusterServiceVersion |
| 25 | + }{ |
| 26 | + { |
| 27 | + name: "CSV with name longer than 63 characters", |
| 28 | + csv: &operatorsv1alpha1.ClusterServiceVersion{ |
| 29 | + TypeMeta: csvType, |
| 30 | + ObjectMeta: metav1.ObjectMeta{ |
| 31 | + Name: "clusterkubedescheduleroperator.4.6.0-202106010807.p0.git.5db84c5", |
| 32 | + Namespace: "test-namespace", |
| 33 | + }, |
| 34 | + }, |
| 35 | + }, |
| 36 | + { |
| 37 | + name: "CSV with invalid name", |
| 38 | + csv: &operatorsv1alpha1.ClusterServiceVersion{ |
| 39 | + TypeMeta: csvType, |
| 40 | + ObjectMeta: metav1.ObjectMeta{ |
| 41 | + Name: "something@somewhere", |
| 42 | + Namespace: "test-namespace", |
| 43 | + }, |
| 44 | + }, |
| 45 | + }, |
| 46 | + { |
| 47 | + name: "CSV with empty string name", |
| 48 | + csv: &operatorsv1alpha1.ClusterServiceVersion{ |
| 49 | + TypeMeta: csvType, |
| 50 | + ObjectMeta: metav1.ObjectMeta{ |
| 51 | + Name: "", |
| 52 | + Namespace: "test-namespace", |
| 53 | + }, |
| 54 | + }, |
| 55 | + }, |
| 56 | + } |
| 57 | + |
| 58 | + for _, tt := range tests { |
| 59 | + t.Run(tt.name, func(t *testing.T) { |
| 60 | + selector := CSVOwnerSelector(tt.csv) |
| 61 | + |
| 62 | + assert.NotNil(t, selector) |
| 63 | + assert.False(t, selector.Empty()) |
| 64 | + }) |
| 65 | + } |
| 66 | +} |
0 commit comments