1
1
package filter
2
2
3
3
import (
4
+ "fmt"
5
+
4
6
mmsemver "github.com/Masterminds/semver/v3"
5
7
bsemver "github.com/blang/semver/v4"
6
8
@@ -11,59 +13,80 @@ import (
11
13
)
12
14
13
15
func WithPackageName (packageName string ) Predicate [catalogmetadata.Bundle ] {
14
- return func (bundle * catalogmetadata.Bundle ) bool {
15
- return bundle .Package == packageName
16
+ return func (bundle * catalogmetadata.Bundle ) (bool , []string ) {
17
+ value := bundle .Package == packageName
18
+ if ! value {
19
+ return false , []string {packageName }
20
+ }
21
+ return value , nil
16
22
}
17
23
}
18
24
19
25
func InMastermindsSemverRange (semverRange * mmsemver.Constraints ) Predicate [catalogmetadata.Bundle ] {
20
- return func (bundle * catalogmetadata.Bundle ) bool {
26
+ return func (bundle * catalogmetadata.Bundle ) ( bool , [] string ) {
21
27
bVersion , err := bundle .Version ()
22
28
if err != nil {
23
- return false
29
+ return false , [] string { err . Error ()}
24
30
}
25
31
// No error should occur here because the simple version was successfully parsed by blang
26
32
// We are unaware of any tests cases that would cause one to fail but not the other
27
33
// This will cause code coverage to drop for this line. We don't ignore the error because
28
34
// there might be that one extreme edge case that might cause one to fail but not the other
29
35
mVersion , err := mmsemver .NewVersion (bVersion .String ())
30
36
if err != nil {
31
- return false
37
+ return false , []string {err .Error ()}
38
+ }
39
+ res := semverRange .Check (mVersion )
40
+ if ! res {
41
+ return false , []string {fmt .Sprintf ("no package %q matching version %q found" , bundle .Package , semverRange .String ())}
32
42
}
33
- return semverRange . Check ( mVersion )
43
+ return true , nil
34
44
}
35
45
}
36
46
37
- func InBlangSemverRange (semverRange bsemver.Range ) Predicate [catalogmetadata.Bundle ] {
38
- return func (bundle * catalogmetadata.Bundle ) bool {
47
+ func InBlangSemverRange (semverRange bsemver.Range , semverRangeString string ) Predicate [catalogmetadata.Bundle ] {
48
+ return func (bundle * catalogmetadata.Bundle ) ( bool , [] string ) {
39
49
bundleVersion , err := bundle .Version ()
40
50
if err != nil {
41
- return false
51
+ return false , [] string { err . Error ()}
42
52
}
43
- return semverRange (* bundleVersion )
53
+ if ! semverRange (* bundleVersion ) {
54
+ return false , []string {fmt .Sprintf ("no package %q matching version %q found" , bundle .Package , semverRangeString )}
55
+ }
56
+ return true , nil
44
57
}
45
58
}
46
59
47
60
func InChannel (channelName string ) Predicate [catalogmetadata.Bundle ] {
48
- return func (bundle * catalogmetadata.Bundle ) bool {
61
+ return func (bundle * catalogmetadata.Bundle ) ( bool , [] string ) {
49
62
for _ , ch := range bundle .InChannels {
50
63
if ch .Name == channelName {
51
- return true
64
+ return true , nil
52
65
}
53
66
}
54
- return false
67
+ return false , [] string { fmt . Sprintf ( "no package %q found in channel %q" , bundle . Package , channelName )}
55
68
}
56
69
}
57
70
58
71
func WithBundleImage (bundleImage string ) Predicate [catalogmetadata.Bundle ] {
59
- return func (bundle * catalogmetadata.Bundle ) bool {
60
- return bundle .Image == bundleImage
72
+ return func (bundle * catalogmetadata.Bundle ) (bool , []string ) {
73
+ res := bundle .Image == bundleImage
74
+ if ! res {
75
+ return false , []string {fmt .Sprintf ("no matching bundle image %q found for package %s" , bundleImage , bundle .Package )}
76
+ } else {
77
+ return true , nil
78
+ }
61
79
}
62
80
}
63
81
64
82
func WithBundleName (bundleName string ) Predicate [catalogmetadata.Bundle ] {
65
- return func (bundle * catalogmetadata.Bundle ) bool {
66
- return bundle .Name == bundleName
83
+ return func (bundle * catalogmetadata.Bundle ) (bool , []string ) {
84
+ res := bundle .Name == bundleName
85
+ if ! res {
86
+ return false , []string {fmt .Sprintf ("no matching bundle name %q found for package %s" , bundleName , bundle .Package )}
87
+ } else {
88
+ return true , nil
89
+ }
67
90
}
68
91
}
69
92
@@ -87,20 +110,25 @@ func LegacySuccessor(installedBundle *ocv1alpha1.BundleMetadata) Predicate[catal
87
110
return false
88
111
}
89
112
90
- return func (candidateBundle * catalogmetadata.Bundle ) bool {
113
+ return func (candidateBundle * catalogmetadata.Bundle ) ( bool , [] string ) {
91
114
for _ , ch := range candidateBundle .InChannels {
92
115
for _ , chEntry := range ch .Entries {
93
116
if candidateBundle .Name == chEntry .Name && isSuccessor (chEntry ) {
94
- return true
117
+ return true , nil
95
118
}
96
119
}
97
120
}
98
- return false
121
+ return false , [] string { fmt . Sprintf ( "no legacy successor found for bundle name %q" , candidateBundle . Name )}
99
122
}
100
123
}
101
124
102
125
func WithDeprecation (deprecated bool ) Predicate [catalogmetadata.Bundle ] {
103
- return func (bundle * catalogmetadata.Bundle ) bool {
104
- return bundle .HasDeprecation () == deprecated
126
+ return func (bundle * catalogmetadata.Bundle ) (bool , []string ) {
127
+ res := bundle .HasDeprecation () == deprecated
128
+ if ! res {
129
+ return false , []string {fmt .Sprintf ("no bundle %q found with desired deprecation status %t" , bundle .Name , deprecated )}
130
+ } else {
131
+ return true , nil
132
+ }
105
133
}
106
134
}
0 commit comments