-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor legacy upgrade constraint semantics (#450)
* Make successors func swappable * Update test to not use Ginkgo & prepare the test to be able to switch between different states of the `ForceSemverUpgradeConstraints` feature flag Signed-off-by: Mikalai Radchuk <[email protected]>
- Loading branch information
Showing
2 changed files
with
141 additions
and
98 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
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 |
---|---|---|
|
@@ -3,116 +3,141 @@ package variablesources_test | |
import ( | ||
"context" | ||
"encoding/json" | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
"github.com/operator-framework/deppy/pkg/deppy" | ||
"github.com/operator-framework/operator-registry/alpha/declcfg" | ||
"github.com/operator-framework/operator-registry/alpha/property" | ||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
featuregatetesting "k8s.io/component-base/featuregate/testing" | ||
|
||
"github.com/operator-framework/operator-controller/internal/catalogmetadata" | ||
olmvariables "github.com/operator-framework/operator-controller/internal/resolution/variables" | ||
"github.com/operator-framework/operator-controller/internal/resolution/variablesources" | ||
"github.com/operator-framework/operator-controller/pkg/features" | ||
testutil "github.com/operator-framework/operator-controller/test/util" | ||
) | ||
|
||
var _ = Describe("InstalledPackageVariableSource", func() { | ||
var ( | ||
ipvs *variablesources.InstalledPackageVariableSource | ||
fakeCatalogClient testutil.FakeCatalogClient | ||
bundleImage string | ||
) | ||
|
||
BeforeEach(func() { | ||
channel := catalogmetadata.Channel{Channel: declcfg.Channel{ | ||
Name: "stable", | ||
Entries: []declcfg.ChannelEntry{ | ||
{ | ||
Name: "test-package.v1.0.0", | ||
}, | ||
{ | ||
Name: "test-package.v2.0.0", | ||
Replaces: "test-package.v1.0.0", | ||
}, | ||
{ | ||
Name: "test-package.v3.0.0", | ||
Replaces: "test-package.v2.0.0", | ||
}, | ||
{ | ||
Name: "test-package.v4.0.0", | ||
Replaces: "test-package.v3.0.0", | ||
}, | ||
{ | ||
Name: "test-package.v5.0.0", | ||
Replaces: "test-package.v4.0.0", | ||
}, | ||
func TestInstalledPackageVariableSource(t *testing.T) { | ||
channel := catalogmetadata.Channel{Channel: declcfg.Channel{ | ||
Name: "stable", | ||
Entries: []declcfg.ChannelEntry{ | ||
{ | ||
Name: "test-package.v1.0.0", | ||
}, | ||
}} | ||
bundleList := []*catalogmetadata.Bundle{ | ||
{Bundle: declcfg.Bundle{ | ||
Name: "test-package.v1.0.0", | ||
Package: "test-package", | ||
Image: "registry.io/repo/[email protected]", | ||
Properties: []property.Property{ | ||
{Type: property.TypePackage, Value: json.RawMessage(`{"packageName": "test-package", "version": "1.0.0"}`)}, | ||
}}, | ||
InChannels: []*catalogmetadata.Channel{&channel}, | ||
{ | ||
Name: "test-package.v2.0.0", | ||
Replaces: "test-package.v1.0.0", | ||
}, | ||
{Bundle: declcfg.Bundle{ | ||
Name: "test-package.v3.0.0", | ||
Package: "test-package", | ||
Image: "registry.io/repo/[email protected]", | ||
Properties: []property.Property{ | ||
{Type: property.TypePackage, Value: json.RawMessage(`{"packageName": "test-package", "version": "3.0.0"}`)}, | ||
}}, | ||
InChannels: []*catalogmetadata.Channel{&channel}, | ||
{ | ||
Name: "test-package.v2.1.0", | ||
Replaces: "test-package.v2.0.0", | ||
}, | ||
{Bundle: declcfg.Bundle{ | ||
Name: "test-package.v2.0.0", | ||
Package: "test-package", | ||
Image: "registry.io/repo/[email protected]", | ||
Properties: []property.Property{ | ||
{Type: property.TypePackage, Value: json.RawMessage(`{"packageName": "test-package", "version": "2.0.0"}`)}, | ||
}}, | ||
InChannels: []*catalogmetadata.Channel{&channel}, | ||
{ | ||
Name: "test-package.v2.2.0", | ||
Replaces: "test-package.v2.1.0", | ||
}, | ||
{Bundle: declcfg.Bundle{ | ||
Name: "test-package.v4.0.0", | ||
Package: "test-package", | ||
Image: "registry.io/repo/[email protected]", | ||
Properties: []property.Property{ | ||
{Type: property.TypePackage, Value: json.RawMessage(`{"packageName": "test-package", "version": "4.0.0"}`)}, | ||
}}, | ||
InChannels: []*catalogmetadata.Channel{&channel}, | ||
{ | ||
Name: "test-package.v3.0.0", | ||
Replaces: "test-package.v2.2.0", | ||
}, | ||
{Bundle: declcfg.Bundle{ | ||
Name: "test-package.v5.0.0", | ||
Package: "test-package", | ||
Image: "registry.io/repo/[email protected]", | ||
Properties: []property.Property{ | ||
{Type: property.TypePackage, Value: json.RawMessage(`{"packageName": "test-package", "version": "5-0.0"}`)}, | ||
}}, | ||
InChannels: []*catalogmetadata.Channel{&channel}, | ||
{ | ||
Name: "test-package.v4.0.0", | ||
Replaces: "test-package.v3.0.0", | ||
}, | ||
} | ||
var err error | ||
bundleImage = "registry.io/repo/[email protected]" | ||
fakeCatalogClient = testutil.NewFakeCatalogClient(bundleList) | ||
ipvs, err = variablesources.NewInstalledPackageVariableSource(&fakeCatalogClient, bundleImage) | ||
Expect(err).NotTo(HaveOccurred()) | ||
}) | ||
{ | ||
Name: "test-package.v5.0.0", | ||
Replaces: "test-package.v4.0.0", | ||
}, | ||
}, | ||
}} | ||
bundleList := []*catalogmetadata.Bundle{ | ||
{Bundle: declcfg.Bundle{ | ||
Name: "test-package.v1.0.0", | ||
Package: "test-package", | ||
Image: "registry.io/repo/[email protected]", | ||
Properties: []property.Property{ | ||
{Type: property.TypePackage, Value: json.RawMessage(`{"packageName": "test-package", "version": "1.0.0"}`)}, | ||
}}, | ||
InChannels: []*catalogmetadata.Channel{&channel}, | ||
}, | ||
{Bundle: declcfg.Bundle{ | ||
Name: "test-package.v3.0.0", | ||
Package: "test-package", | ||
Image: "registry.io/repo/[email protected]", | ||
Properties: []property.Property{ | ||
{Type: property.TypePackage, Value: json.RawMessage(`{"packageName": "test-package", "version": "3.0.0"}`)}, | ||
}}, | ||
InChannels: []*catalogmetadata.Channel{&channel}, | ||
}, | ||
{Bundle: declcfg.Bundle{ | ||
Name: "test-package.v2.0.0", | ||
Package: "test-package", | ||
Image: "registry.io/repo/[email protected]", | ||
Properties: []property.Property{ | ||
{Type: property.TypePackage, Value: json.RawMessage(`{"packageName": "test-package", "version": "2.0.0"}`)}, | ||
}}, | ||
InChannels: []*catalogmetadata.Channel{&channel}, | ||
}, | ||
{Bundle: declcfg.Bundle{ | ||
Name: "test-package.v2.1.0", | ||
Package: "test-package", | ||
Image: "registry.io/repo/[email protected]", | ||
Properties: []property.Property{ | ||
{Type: property.TypePackage, Value: json.RawMessage(`{"packageName": "test-package", "version": "2.1.0"}`)}, | ||
}}, | ||
InChannels: []*catalogmetadata.Channel{&channel}, | ||
}, | ||
{Bundle: declcfg.Bundle{ | ||
Name: "test-package.v2.2.0", | ||
Package: "test-package", | ||
Image: "registry.io/repo/[email protected]", | ||
Properties: []property.Property{ | ||
{Type: property.TypePackage, Value: json.RawMessage(`{"packageName": "test-package", "version": "2.2.0"}`)}, | ||
}}, | ||
InChannels: []*catalogmetadata.Channel{&channel}, | ||
}, | ||
{Bundle: declcfg.Bundle{ | ||
Name: "test-package.v4.0.0", | ||
Package: "test-package", | ||
Image: "registry.io/repo/[email protected]", | ||
Properties: []property.Property{ | ||
{Type: property.TypePackage, Value: json.RawMessage(`{"packageName": "test-package", "version": "4.0.0"}`)}, | ||
}}, | ||
InChannels: []*catalogmetadata.Channel{&channel}, | ||
}, | ||
{Bundle: declcfg.Bundle{ | ||
Name: "test-package.v5.0.0", | ||
Package: "test-package", | ||
Image: "registry.io/repo/[email protected]", | ||
Properties: []property.Property{ | ||
{Type: property.TypePackage, Value: json.RawMessage(`{"packageName": "test-package", "version": "5-0.0"}`)}, | ||
}}, | ||
InChannels: []*catalogmetadata.Channel{&channel}, | ||
}, | ||
} | ||
|
||
const bundleImage = "registry.io/repo/[email protected]" | ||
fakeCatalogClient := testutil.NewFakeCatalogClient(bundleList) | ||
|
||
t.Run("with ForceSemverUpgradeConstraints feature gate disabled", func(t *testing.T) { | ||
defer featuregatetesting.SetFeatureGateDuringTest(t, features.OperatorControllerFeatureGate, features.ForceSemverUpgradeConstraints, false)() | ||
|
||
ipvs, err := variablesources.NewInstalledPackageVariableSource(&fakeCatalogClient, bundleImage) | ||
require.NoError(t, err) | ||
|
||
It("should return the correct package variable", func() { | ||
variables, err := ipvs.GetVariables(context.TODO()) | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(variables).To(HaveLen(1)) | ||
reqPackageVar, ok := variables[0].(*olmvariables.InstalledPackageVariable) | ||
Expect(ok).To(BeTrue()) | ||
Expect(reqPackageVar.Identifier()).To(Equal(deppy.IdentifierFromString("installed package test-package"))) | ||
require.NoError(t, err) | ||
require.Len(t, variables, 1) | ||
packageVariable, ok := variables[0].(*olmvariables.InstalledPackageVariable) | ||
assert.True(t, ok) | ||
assert.Equal(t, deppy.IdentifierFromString("installed package test-package"), packageVariable.Identifier()) | ||
|
||
// ensure bundles are in version order (high to low) | ||
Expect(reqPackageVar.Bundles()).To(HaveLen(2)) | ||
Expect(reqPackageVar.Bundles()[0].Name).To(Equal("test-package.v3.0.0")) | ||
Expect(reqPackageVar.Bundles()[1].Name).To(Equal("test-package.v2.0.0")) | ||
bundles := packageVariable.Bundles() | ||
require.Len(t, bundles, 2) | ||
assert.Equal(t, "test-package.v2.1.0", packageVariable.Bundles()[0].Name) | ||
assert.Equal(t, "test-package.v2.0.0", packageVariable.Bundles()[1].Name) | ||
}) | ||
}) | ||
} |