Skip to content

Commit

Permalink
update unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: everettraven <everettraven@gmail.com>
  • Loading branch information
everettraven committed Jan 31, 2024
1 parent c04a2ce commit 08996d5
Show file tree
Hide file tree
Showing 8 changed files with 437 additions and 114 deletions.
29 changes: 4 additions & 25 deletions internal/catalogmetadata/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,27 +52,6 @@ func TestClient(t *testing.T) {
fetcher: &MockFetcher{shouldError: true},
wantErr: "error fetching catalog contents: mock cache error",
},
{
name: "channel has a ref to a missing bundle",
fakeCatalog: func() ([]client.Object, []*catalogmetadata.Bundle, map[string][]byte) {
objs, _, catalogContentMap := defaultFakeCatalog()

catalogContentMap["catalog-1"] = append(catalogContentMap["catalog-1"], []byte(`{
"schema": "olm.channel",
"name": "channel-with-missing-bundle",
"package": "fake1",
"entries": [
{
"name": "fake1.v9.9.9"
}
]
}`)...)

return objs, nil, catalogContentMap
},
wantErr: `bundle "fake1.v9.9.9" not found in catalog "catalog-1" (package "fake1", channel "channel-with-missing-bundle")`,
fetcher: &MockFetcher{},
},
{
name: "invalid meta",
fakeCatalog: func() ([]client.Object, []*catalogmetadata.Bundle, map[string][]byte) {
Expand Down Expand Up @@ -132,10 +111,10 @@ func TestClient(t *testing.T) {
objs, bundles, catalogContentMap := defaultFakeCatalog()

catalogContentMap["catalog-1"] = append(catalogContentMap["catalog-1"],
[]byte(`{"schema": "olm.deprecations", "package":"fake1", "entries":[{"message": "fake1 is deprecated", "reference": {"schema": "olm.package"}}, {"message":"channel stable is deprecated", "reference": {"schema": "olm.channel", "name": "stable"}}, {"message": "bundle fake1.v1.0.0 is deprecated", "reference":{"schema":"olm.bundle", "name":"fake1.v1.0.0"}}]}`)...)
[]byte(`{"schema": "olm.deprecations", "package":"fake1", "entries":[{"message": "bundle fake1.v1.0.0 is deprecated", "reference":{"schema":"olm.bundle", "name":"fake1.v1.0.0"}}]}`)...)

for i := range bundles {
if bundles[i].Name == "fake1.v1.0.0" {
if bundles[i].Name == "fake1.v1.0.0" && bundles[i].Catalog == "catalog-1" {
bundles[i].Deprecation = &declcfg.DeprecationEntry{
Reference: declcfg.PackageScopedReference{
Schema: "olm.bundle",
Expand All @@ -161,10 +140,10 @@ func TestClient(t *testing.T) {
tt.fetcher,
)

bundles, err := fakeCatalogClient.CatalogContents(ctx)
contents, err := fakeCatalogClient.CatalogContents(ctx)
if tt.wantErr == "" {
assert.NoError(t, err)
assert.Equal(t, expectedBundles, bundles)
assert.Equal(t, expectedBundles, contents.Bundles)
} else {
assert.EqualError(t, err, tt.wantErr)
}
Expand Down
4 changes: 2 additions & 2 deletions internal/controllers/clusterextension_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ func SetDeprecationStatus(ext *ocv1alpha1.ClusterExtension, bundle *catalogmetad
},
)
if len(channels) > 0 {
if packages[0].IsDeprecated() {
if channels[0].IsDeprecated() {
apimeta.SetStatusCondition(&ext.Status.Conditions, metav1.Condition{
Type: ocv1alpha1.TypeChannelDeprecated,
Reason: ocv1alpha1.ReasonDeprecated,
Expand All @@ -353,7 +353,7 @@ func SetDeprecationStatus(ext *ocv1alpha1.ClusterExtension, bundle *catalogmetad

if bundle.IsDeprecated() {
apimeta.SetStatusCondition(&ext.Status.Conditions, metav1.Condition{
Type: ocv1alpha1.TypeChannelDeprecated,
Type: ocv1alpha1.TypeBundleDeprecated,
Reason: ocv1alpha1.ReasonDeprecated,
Status: metav1.ConditionTrue,
Message: bundle.Deprecation.Message,
Expand Down
Loading

0 comments on commit 08996d5

Please sign in to comment.