Skip to content

Commit

Permalink
fixup! Turn installed package variable source into a func
Browse files Browse the repository at this point in the history
  • Loading branch information
m1kola committed Nov 6, 2023
1 parent deb7a6f commit 220ee92
Showing 1 changed file with 42 additions and 24 deletions.
66 changes: 42 additions & 24 deletions internal/resolution/variablesources/installed_package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package variablesources_test

import (
"encoding/json"
"fmt"
"testing"

"github.com/operator-framework/deppy/pkg/deppy"
Expand Down Expand Up @@ -202,37 +201,36 @@ func TestMakeInstalledPackageVariables(t *testing.T) {
},
}

fakeBundleDeployments := func(bundleImages ...string) []rukpakv1alpha1.BundleDeployment {
bundleDeployments := []rukpakv1alpha1.BundleDeployment{}
for idx, bundleImage := range bundleImages {
bd := rukpakv1alpha1.BundleDeployment{
ObjectMeta: metav1.ObjectMeta{
Name: fmt.Sprintf("bd-%d", idx),
},
Spec: rukpakv1alpha1.BundleDeploymentSpec{
Template: &rukpakv1alpha1.BundleTemplate{
Spec: rukpakv1alpha1.BundleSpec{
Source: rukpakv1alpha1.BundleSource{
Image: &rukpakv1alpha1.ImageSource{
Ref: bundleImage,
},
fakeBundleDeployment := func(name, bundleImage string) rukpakv1alpha1.BundleDeployment {
return rukpakv1alpha1.BundleDeployment{
ObjectMeta: metav1.ObjectMeta{
Name: name,
},
Spec: rukpakv1alpha1.BundleDeploymentSpec{
Template: &rukpakv1alpha1.BundleTemplate{
Spec: rukpakv1alpha1.BundleSpec{
Source: rukpakv1alpha1.BundleSource{
Image: &rukpakv1alpha1.ImageSource{
Ref: bundleImage,
},
},
},
},
}
bundleDeployments = append(bundleDeployments, bd)
},
}

return bundleDeployments
}

t.Run("with ForceSemverUpgradeConstraints feature gate enabled", func(t *testing.T) {
defer featuregatetesting.SetFeatureGateDuringTest(t, features.OperatorControllerFeatureGate, features.ForceSemverUpgradeConstraints, true)()

t.Run("with non-zero major version", func(t *testing.T) {
const bundleImage = "registry.io/repo/test-package@v2.0.0"
installedPackages, err := variablesources.MakeInstalledPackageVariables(allBundles, fakeBundleDeployments(bundleImage))
installedPackages, err := variablesources.MakeInstalledPackageVariables(
allBundles,
[]rukpakv1alpha1.BundleDeployment{
fakeBundleDeployment("test-bd", bundleImage),
},
)
require.NoError(t, err)

require.Len(t, installedPackages, 1)
Expand All @@ -250,7 +248,12 @@ func TestMakeInstalledPackageVariables(t *testing.T) {
t.Run("with zero major version", func(t *testing.T) {
t.Run("with zero minor version", func(t *testing.T) {
const bundleImage = "registry.io/repo/test-package@v0.0.1"
installedPackages, err := variablesources.MakeInstalledPackageVariables(allBundles, fakeBundleDeployments(bundleImage))
installedPackages, err := variablesources.MakeInstalledPackageVariables(
allBundles,
[]rukpakv1alpha1.BundleDeployment{
fakeBundleDeployment("test-bd", bundleImage),
},
)
require.NoError(t, err)

require.Len(t, installedPackages, 1)
Expand All @@ -265,7 +268,12 @@ func TestMakeInstalledPackageVariables(t *testing.T) {

t.Run("with non-zero minor version", func(t *testing.T) {
const bundleImage = "registry.io/repo/test-package@v0.1.0"
installedPackages, err := variablesources.MakeInstalledPackageVariables(allBundles, fakeBundleDeployments(bundleImage))
installedPackages, err := variablesources.MakeInstalledPackageVariables(
allBundles,
[]rukpakv1alpha1.BundleDeployment{
fakeBundleDeployment("test-bd", bundleImage),
},
)
require.NoError(t, err)

require.Len(t, installedPackages, 1)
Expand All @@ -285,7 +293,12 @@ func TestMakeInstalledPackageVariables(t *testing.T) {
defer featuregatetesting.SetFeatureGateDuringTest(t, features.OperatorControllerFeatureGate, features.ForceSemverUpgradeConstraints, false)()

const bundleImage = "registry.io/repo/test-package@v2.0.0"
installedPackages, err := variablesources.MakeInstalledPackageVariables(allBundles, fakeBundleDeployments(bundleImage))
installedPackages, err := variablesources.MakeInstalledPackageVariables(
allBundles,
[]rukpakv1alpha1.BundleDeployment{
fakeBundleDeployment("test-bd", bundleImage),
},
)
require.NoError(t, err)

require.Len(t, installedPackages, 1)
Expand All @@ -301,7 +314,12 @@ func TestMakeInstalledPackageVariables(t *testing.T) {

t.Run("installed bundle not found", func(t *testing.T) {
const bundleImage = "registry.io/repo/test-package@v9.0.0"
installedPackages, err := variablesources.MakeInstalledPackageVariables(allBundles, fakeBundleDeployments(bundleImage))
installedPackages, err := variablesources.MakeInstalledPackageVariables(
allBundles,
[]rukpakv1alpha1.BundleDeployment{
fakeBundleDeployment("test-bd", bundleImage),
},
)
assert.Nil(t, installedPackages)
assert.ErrorContains(t, err, `bundleImage "registry.io/repo/test-package@v9.0.0" not found`)
})
Expand Down

0 comments on commit 220ee92

Please sign in to comment.