5
5
"fmt"
6
6
"strings"
7
7
"testing"
8
+ "time"
8
9
9
10
"github.com/stretchr/testify/require"
10
11
appsv1 "k8s.io/api/apps/v1"
@@ -17,6 +18,7 @@ import (
17
18
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
18
19
"k8s.io/apimachinery/pkg/runtime"
19
20
"k8s.io/apimachinery/pkg/util/wait"
21
+ "k8s.io/apimachinery/pkg/watch"
20
22
21
23
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1"
22
24
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1alpha1"
@@ -1217,9 +1219,31 @@ func TestCreateCSVWithOwnedAPIService(t *testing.T) {
1217
1219
csv .SetName (depName )
1218
1220
1219
1221
// Create the APIService CSV
1220
- cleanupCSV , err := createCSV (t , c , crc , csv , testNamespace , false , true )
1222
+ cleanupCSV , err := createCSV (t , c , crc , csv , testNamespace , false , false )
1221
1223
require .NoError (t , err )
1222
- defer cleanupCSV ()
1224
+ defer func () {
1225
+ watcher , err := c .ApiregistrationV1Interface ().ApiregistrationV1 ().APIServices ().Watch (metav1.ListOptions {FieldSelector : "metadata.name=" + apiServiceName })
1226
+ require .NoError (t , err )
1227
+
1228
+ deleted := make (chan struct {})
1229
+ go func () {
1230
+ events := watcher .ResultChan ()
1231
+ for {
1232
+ select {
1233
+ case evt := <- events :
1234
+ if evt .Type == watch .Deleted {
1235
+ deleted <- struct {}{}
1236
+ return
1237
+ }
1238
+ case <- time .After (pollDuration ):
1239
+ require .FailNow (t , "apiservice not cleaned up after CSV deleted" )
1240
+ }
1241
+ }
1242
+ }()
1243
+
1244
+ cleanupCSV ()
1245
+ <- deleted
1246
+ }()
1223
1247
1224
1248
fetchedCSV , err := fetchCSV (t , crc , csv .Name , testNamespace , csvSucceededChecker )
1225
1249
require .NoError (t , err )
0 commit comments