Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add extra tests for zero major version #472

Merged
merged 1 commit into from
Oct 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
139 changes: 123 additions & 16 deletions internal/resolution/variablesources/installed_package_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,27 @@ func TestInstalledPackageVariableSource(t *testing.T) {
Name: "stable",
Entries: []declcfg.ChannelEntry{
{
Name: "test-package.v1.0.0",
Name: "test-package.v0.0.1",
},
{
Name: "test-package.v0.0.2",
Replaces: "test-package.v0.0.1",
},
{
Name: "test-package.v0.1.0",
Replaces: "test-package.v0.0.2",
},
{
Name: "test-package.v0.1.1",
Replaces: "test-package.v0.1.0",
},
{
Name: "test-package.v0.2.0",
Replaces: "test-package.v0.1.1",
},
{
Name: "test-package.v1.0.0",
Replaces: "test-package.v0.2.0",
},
{
Name: "test-package.v2.0.0",
Expand Down Expand Up @@ -53,6 +73,51 @@ func TestInstalledPackageVariableSource(t *testing.T) {
},
}}
bundleList := []*catalogmetadata.Bundle{
{Bundle: declcfg.Bundle{
Name: "test-package.v0.0.1",
Package: "test-package",
Image: "registry.io/repo/test-package@v0.0.1",
Properties: []property.Property{
{Type: property.TypePackage, Value: json.RawMessage(`{"packageName": "test-package", "version": "0.0.1"}`)},
}},
InChannels: []*catalogmetadata.Channel{&channel},
},
{Bundle: declcfg.Bundle{
Name: "test-package.v0.0.2",
Package: "test-package",
Image: "registry.io/repo/test-package@v0.0.2",
Properties: []property.Property{
{Type: property.TypePackage, Value: json.RawMessage(`{"packageName": "test-package", "version": "0.0.2"}`)},
}},
InChannels: []*catalogmetadata.Channel{&channel},
},
{Bundle: declcfg.Bundle{
Name: "test-package.v0.1.0",
Package: "test-package",
Image: "registry.io/repo/test-package@v0.1.0",
Properties: []property.Property{
{Type: property.TypePackage, Value: json.RawMessage(`{"packageName": "test-package", "version": "0.1.0"}`)},
}},
InChannels: []*catalogmetadata.Channel{&channel},
},
{Bundle: declcfg.Bundle{
Name: "test-package.v0.1.1",
Package: "test-package",
Image: "registry.io/repo/test-package@v0.1.1",
Properties: []property.Property{
{Type: property.TypePackage, Value: json.RawMessage(`{"packageName": "test-package", "version": "0.1.1"}`)},
}},
InChannels: []*catalogmetadata.Channel{&channel},
},
{Bundle: declcfg.Bundle{
Name: "test-package.v0.2.0",
Package: "test-package",
Image: "registry.io/repo/test-package@v0.2.0",
Properties: []property.Property{
{Type: property.TypePackage, Value: json.RawMessage(`{"packageName": "test-package", "version": "0.2.0"}`)},
}},
InChannels: []*catalogmetadata.Channel{&channel},
},
{Bundle: declcfg.Bundle{
Name: "test-package.v1.0.0",
Package: "test-package",
Expand Down Expand Up @@ -118,33 +183,75 @@ func TestInstalledPackageVariableSource(t *testing.T) {
},
}

const bundleImage = "registry.io/repo/test-package@v2.0.0"
fakeCatalogClient := testutil.NewFakeCatalogClient(bundleList)

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

ipvs, err := variablesources.NewInstalledPackageVariableSource(&fakeCatalogClient, bundleImage)
require.NoError(t, err)
t.Run("with non-zero major version", func(t *testing.T) {
const bundleImage = "registry.io/repo/test-package@v2.0.0"
ipvs, err := variablesources.NewInstalledPackageVariableSource(&fakeCatalogClient, bundleImage)
require.NoError(t, err)

variables, err := ipvs.GetVariables(context.TODO())
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())
variables, err := ipvs.GetVariables(context.TODO())
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)
bundles := packageVariable.Bundles()
require.Len(t, bundles, 3)
assert.Equal(t, "test-package.v2.2.0", packageVariable.Bundles()[0].Name)
assert.Equal(t, "test-package.v2.1.0", packageVariable.Bundles()[1].Name)
assert.Equal(t, "test-package.v2.0.0", packageVariable.Bundles()[2].Name)
// ensure bundles are in version order (high to low)
bundles := packageVariable.Bundles()
require.Len(t, bundles, 3)
assert.Equal(t, "test-package.v2.2.0", packageVariable.Bundles()[0].Name)
assert.Equal(t, "test-package.v2.1.0", packageVariable.Bundles()[1].Name)
assert.Equal(t, "test-package.v2.0.0", packageVariable.Bundles()[2].Name)
Comment on lines +193 to +208
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This piece was shifted right into a sub test. Might be easier to review this PR ignoring whitespace changes (GH has a checkbox under the cog for this or usign git diff -w)

})

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"
ipvs, err := variablesources.NewInstalledPackageVariableSource(&fakeCatalogClient, bundleImage)
require.NoError(t, err)

variables, err := ipvs.GetVariables(context.TODO())
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())

// No upgrades are allowed in major version zero when minor version is also zero
bundles := packageVariable.Bundles()
require.Len(t, bundles, 1)
assert.Equal(t, "test-package.v0.0.1", packageVariable.Bundles()[0].Name)
})

t.Run("with non-zero minor version", func(t *testing.T) {
const bundleImage = "registry.io/repo/test-package@v0.1.0"
ipvs, err := variablesources.NewInstalledPackageVariableSource(&fakeCatalogClient, bundleImage)
require.NoError(t, err)

variables, err := ipvs.GetVariables(context.TODO())
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())

// Patch version upgrades are allowed, but not minor upgrades
bundles := packageVariable.Bundles()
require.Len(t, bundles, 2)
assert.Equal(t, "test-package.v0.1.1", packageVariable.Bundles()[0].Name)
assert.Equal(t, "test-package.v0.1.0", packageVariable.Bundles()[1].Name)
})
})
})

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

const bundleImage = "registry.io/repo/test-package@v2.0.0"
ipvs, err := variablesources.NewInstalledPackageVariableSource(&fakeCatalogClient, bundleImage)
require.NoError(t, err)

Expand Down