@@ -2,19 +2,14 @@ package resolver
2
2
3
3
import (
4
4
"context"
5
- "encoding/json"
6
5
"fmt"
7
6
"testing"
8
7
9
- "github.com/blang/semver/v4"
10
8
"github.com/operator-framework/operator-registry/pkg/api"
11
9
"github.com/operator-framework/operator-registry/pkg/client"
12
10
opregistry "github.com/operator-framework/operator-registry/pkg/registry"
13
11
"github.com/stretchr/testify/require"
14
- metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
15
12
16
- "github.com/operator-framework/api/pkg/lib/version"
17
- "github.com/operator-framework/api/pkg/operators/v1alpha1"
18
13
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry"
19
14
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry/resolver/fakes"
20
15
)
@@ -344,178 +339,3 @@ func TestNamespaceSourceQuerier_FindPackage(t *testing.T) {
344
339
})
345
340
}
346
341
}
347
-
348
- func TestNamespaceSourceQuerier_FindReplacement (t * testing.T ) {
349
- // TODO: clean up this test setup
350
- initialSource := fakes.FakeClientInterface {}
351
- otherSource := fakes.FakeClientInterface {}
352
- replacementSource := fakes.FakeClientInterface {}
353
- replacementAndLatestSource := fakes.FakeClientInterface {}
354
- replacementAndNoAnnotationLatestSource := fakes.FakeClientInterface {}
355
-
356
- latestVersion := semver .MustParse ("1.0.0-1556661308" )
357
- csv := v1alpha1.ClusterServiceVersion {
358
- TypeMeta : metav1.TypeMeta {
359
- Kind : v1alpha1 .ClusterServiceVersionKind ,
360
- APIVersion : v1alpha1 .GroupVersion ,
361
- },
362
- ObjectMeta : metav1.ObjectMeta {
363
- Name : "latest" ,
364
- Namespace : "placeholder" ,
365
- Annotations : map [string ]string {
366
- "olm.skipRange" : ">= 1.0.0-0 < 1.0.0-1556661308" ,
367
- },
368
- },
369
- Spec : v1alpha1.ClusterServiceVersionSpec {
370
- CustomResourceDefinitions : v1alpha1.CustomResourceDefinitions {
371
- Owned : []v1alpha1.CRDDescription {},
372
- Required : []v1alpha1.CRDDescription {},
373
- },
374
- APIServiceDefinitions : v1alpha1.APIServiceDefinitions {
375
- Owned : []v1alpha1.APIServiceDescription {},
376
- Required : []v1alpha1.APIServiceDescription {},
377
- },
378
- Version : version.OperatorVersion {latestVersion },
379
- },
380
- }
381
- csvJson , err := json .Marshal (csv )
382
- require .NoError (t , err )
383
-
384
- nextBundle := & api.Bundle {CsvName : "test.v1" , PackageName : "testPkg" , ChannelName : "testChannel" }
385
- latestBundle := & api.Bundle {CsvName : "latest" , PackageName : "testPkg" , ChannelName : "testChannel" , CsvJson : string (csvJson ), Object : []string {string (csvJson )}, SkipRange : ">= 1.0.0-0 < 1.0.0-1556661308" , Version : latestVersion .String ()}
386
-
387
- csv .SetAnnotations (map [string ]string {})
388
- csvUnstNoAnnotationJson , err := json .Marshal (csv )
389
- require .NoError (t , err )
390
- latestBundleNoAnnotation := & api.Bundle {CsvName : "latest" , PackageName : "testPkg" , ChannelName : "testChannel" , CsvJson : string (csvUnstNoAnnotationJson ), Object : []string {string (csvUnstNoAnnotationJson )}}
391
-
392
- initialSource .GetReplacementBundleInPackageChannelStub = func (ctx context.Context , bundleName , pkgName , channelName string ) (* api.Bundle , error ) {
393
- return nil , fmt .Errorf ("not found" )
394
- }
395
- replacementSource .GetReplacementBundleInPackageChannelStub = func (ctx context.Context , bundleName , pkgName , channelName string ) (* api.Bundle , error ) {
396
- return nextBundle , nil
397
- }
398
- initialSource .GetBundleInPackageChannelStub = func (ctx context.Context , pkgName , channelName string ) (* api.Bundle , error ) {
399
- if pkgName != latestBundle .PackageName {
400
- return nil , fmt .Errorf ("not found" )
401
- }
402
- return latestBundle , nil
403
- }
404
- otherSource .GetBundleInPackageChannelStub = func (ctx context.Context , pkgName , channelName string ) (* api.Bundle , error ) {
405
- if pkgName != latestBundle .PackageName {
406
- return nil , fmt .Errorf ("not found" )
407
- }
408
- return latestBundle , nil
409
- }
410
- replacementAndLatestSource .GetReplacementBundleInPackageChannelStub = func (ctx context.Context , bundleName , pkgName , channelName string ) (* api.Bundle , error ) {
411
- return nextBundle , nil
412
- }
413
- replacementAndLatestSource .GetBundleInPackageChannelStub = func (ctx context.Context , pkgName , channelName string ) (* api.Bundle , error ) {
414
- return latestBundle , nil
415
- }
416
- replacementAndNoAnnotationLatestSource .GetReplacementBundleInPackageChannelStub = func (ctx context.Context , bundleName , pkgName , channelName string ) (* api.Bundle , error ) {
417
- return nextBundle , nil
418
- }
419
- replacementAndNoAnnotationLatestSource .GetBundleInPackageChannelStub = func (ctx context.Context , pkgName , channelName string ) (* api.Bundle , error ) {
420
- return latestBundleNoAnnotation , nil
421
- }
422
-
423
- initialKey := registry.CatalogKey {"initial" , "ns" }
424
- otherKey := registry.CatalogKey {"other" , "other" }
425
- replacementKey := registry.CatalogKey {"replacement" , "ns" }
426
- replacementAndLatestKey := registry.CatalogKey {"replat" , "ns" }
427
- replacementAndNoAnnotationLatestKey := registry.CatalogKey {"replatbad" , "ns" }
428
-
429
- sources := map [registry.CatalogKey ]registry.ClientInterface {
430
- initialKey : & initialSource ,
431
- otherKey : & otherSource ,
432
- replacementKey : & replacementSource ,
433
- replacementAndLatestKey : & replacementAndLatestSource ,
434
- replacementAndNoAnnotationLatestKey : & replacementAndNoAnnotationLatestSource ,
435
- }
436
-
437
- startVersion := semver .MustParse ("1.0.0-0" )
438
- notInRange := semver .MustParse ("1.0.0-1556661347" )
439
-
440
- type fields struct {
441
- sources map [registry.CatalogKey ]registry.ClientInterface
442
- }
443
- type args struct {
444
- currentVersion * semver.Version
445
- pkgName string
446
- channelName string
447
- bundleName string
448
- initialSource registry.CatalogKey
449
- }
450
- type out struct {
451
- bundle * api.Bundle
452
- key * registry.CatalogKey
453
- err error
454
- }
455
- tests := []struct {
456
- name string
457
- fields fields
458
- args args
459
- out out
460
- }{
461
- {
462
- name : "FindsLatestInPrimaryCatalog" ,
463
- fields : fields {sources : sources },
464
- args : args {& startVersion , "testPkg" , "testChannel" , "test.v1" , initialKey },
465
- out : out {bundle : latestBundle , key : & initialKey , err : nil },
466
- },
467
- {
468
- name : "FindsLatestInSecondaryCatalog" ,
469
- fields : fields {sources : sources },
470
- args : args {& startVersion , "testPkg" , "testChannel" , "test.v1" , otherKey },
471
- out : out {bundle : latestBundle , key : & otherKey , err : nil },
472
- },
473
- {
474
- name : "PrefersLatestToReplaced/SameCatalog" ,
475
- fields : fields {sources : sources },
476
- args : args {& startVersion , "testPkg" , "testChannel" , "test.v1" , replacementAndLatestKey },
477
- out : out {bundle : latestBundle , key : & replacementAndLatestKey , err : nil },
478
- },
479
- {
480
- name : "PrefersLatestToReplaced/OtherCatalog" ,
481
- fields : fields {sources : sources },
482
- args : args {& startVersion , "testPkg" , "testChannel" , "test.v1" , initialKey },
483
- out : out {bundle : latestBundle , key : & initialKey , err : nil },
484
- },
485
- {
486
- name : "IgnoresLatestWithoutAnnotation" ,
487
- fields : fields {sources : sources },
488
- args : args {& startVersion , "testPkg" , "testChannel" , "test.v1" , replacementAndNoAnnotationLatestKey },
489
- out : out {bundle : nextBundle , key : & replacementAndNoAnnotationLatestKey , err : nil },
490
- },
491
- {
492
- name : "IgnoresLatestNotInRange" ,
493
- fields : fields {sources : sources },
494
- args : args {& notInRange , "testPkg" , "testChannel" , "test.v1" , replacementAndLatestKey },
495
- out : out {bundle : nextBundle , key : & replacementAndLatestKey , err : nil },
496
- },
497
- {
498
- name : "IgnoresLatestAtLatest" ,
499
- fields : fields {sources : sources },
500
- args : args {& latestVersion , "testPkg" , "testChannel" , "test.v1" , otherKey },
501
- out : out {bundle : nil , key : nil , err : nil },
502
- },
503
- }
504
- for _ , tt := range tests {
505
- t .Run (tt .name , func (t * testing.T ) {
506
- q := & NamespaceSourceQuerier {
507
- sources : tt .fields .sources ,
508
- }
509
- var got * api.Bundle
510
- var key * registry.CatalogKey
511
- var err error
512
- got , key , err = q .FindReplacement (tt .args .currentVersion , tt .args .bundleName , tt .args .pkgName , tt .args .channelName , tt .args .initialSource )
513
- if err != nil {
514
- t .Log (err .Error ())
515
- }
516
- require .Equal (t , tt .out .err , err , "%v" , err )
517
- require .Equal (t , tt .out .bundle , got )
518
- require .Equal (t , tt .out .key , key )
519
- })
520
- }
521
- }
0 commit comments