-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixup! Turn installed package variable source into a func
- Loading branch information
Mikalai Radchuk
committed
Nov 6, 2023
1 parent
deb7a6f
commit 220ee92
Showing
1 changed file
with
42 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ package variablesources_test | |
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/operator-framework/deppy/pkg/deppy" | ||
|
@@ -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/[email protected]" | ||
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) | ||
|
@@ -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/[email protected]" | ||
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) | ||
|
@@ -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/[email protected]" | ||
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) | ||
|
@@ -285,7 +293,12 @@ func TestMakeInstalledPackageVariables(t *testing.T) { | |
defer featuregatetesting.SetFeatureGateDuringTest(t, features.OperatorControllerFeatureGate, features.ForceSemverUpgradeConstraints, false)() | ||
|
||
const bundleImage = "registry.io/repo/[email protected]" | ||
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) | ||
|
@@ -301,7 +314,12 @@ func TestMakeInstalledPackageVariables(t *testing.T) { | |
|
||
t.Run("installed bundle not found", func(t *testing.T) { | ||
const bundleImage = "registry.io/repo/[email protected]" | ||
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/[email protected]" not found`) | ||
}) | ||
|