Skip to content

Commit

Permalink
fix(diff): adds empty channel pruning with an include config on lates…
Browse files Browse the repository at this point in the history
…t mode (#958)

Fixes #957

Signed-off-by: Jennifer Power <barnabei.jennifer@gmail.com>
  • Loading branch information
jpower432 committed May 19, 2022
1 parent 0b2f43f commit d7a3c0b
Show file tree
Hide file tree
Showing 2 changed files with 150 additions and 11 deletions.
21 changes: 10 additions & 11 deletions alpha/declcfg/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,20 +99,19 @@ func (g *DiffGenerator) Run(oldModel, newModel model.Model) (model.Model, error)
if err := latestPruneFromOutput(); err != nil {
return nil, err
}
} else {
for _, outputPkg := range outputModel {
for _, ch := range outputPkg.Channels {
if len(ch.Bundles) == 0 {
delete(outputPkg.Channels, ch.Name)
}
}
if len(outputPkg.Channels) == 0 {
// Remove empty packages.
delete(outputModel, outputPkg.Name)
}

for _, outputPkg := range outputModel {
for _, ch := range outputPkg.Channels {
if len(ch.Bundles) == 0 {
delete(outputPkg.Channels, ch.Name)
}
}
if len(outputPkg.Channels) == 0 {
// Remove empty packages.
delete(outputModel, outputPkg.Name)
}
}

case isInclude: // Add included objects to outputModel.

// Assume heads-only is false for include additively since we already have the channel heads
Expand Down
140 changes: 140 additions & 0 deletions alpha/declcfg/diff_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,76 @@ func TestDiffLatest(t *testing.T) {
g: &DiffGenerator{},
expCfg: DeclarativeConfig{},
},
{
name: "HasDiff/EmptyChannel",
oldCfg: DeclarativeConfig{},
newCfg: DeclarativeConfig{
Packages: []Package{
{Schema: schemaPackage, Name: "foo", DefaultChannel: "stable"},
},
Channels: []Channel{
{Schema: schemaChannel, Name: "stable", Package: "foo", Entries: []ChannelEntry{
{Name: "foo.v0.2.0"},
}},
{Schema: schemaChannel, Name: "v1", Package: "foo", Entries: []ChannelEntry{
{Name: "foo.v0.1.0"},
}},
},
Bundles: []Bundle{
{
Schema: schemaBundle,
Name: "foo.v0.1.0",
Package: "foo",
Image: "reg/foo:latest",
Properties: []property.Property{
property.MustBuildPackage("foo", "0.1.0"),
},
},
{
Schema: schemaBundle,
Name: "foo.v0.2.0",
Package: "foo",
Image: "reg/foo:latest",
Properties: []property.Property{
property.MustBuildPackage("foo", "0.2.0"),
},
},
},
},
g: &DiffGenerator{
Includer: DiffIncluder{
Packages: []DiffIncludePackage{
{
Name: "foo",
AllChannels: DiffIncludeChannel{
Versions: []semver.Version{semver.MustParse("0.2.0")},
},
},
},
},
},
expCfg: DeclarativeConfig{
Packages: []Package{
{Schema: schemaPackage, Name: "foo", DefaultChannel: "stable"},
},
Channels: []Channel{
{Schema: schemaChannel, Name: "stable", Package: "foo", Entries: []ChannelEntry{
{Name: "foo.v0.2.0"},
}},
},
Bundles: []Bundle{
{
Schema: schemaBundle,
Name: "foo.v0.2.0",
Package: "foo",
Image: "reg/foo:latest",
Properties: []property.Property{
property.MustBuildPackage("foo", "0.2.0"),
},
},
},
},
},
{
name: "HasDiff/OneModifiedBundle",
oldCfg: DeclarativeConfig{
Expand Down Expand Up @@ -1332,6 +1402,76 @@ func TestDiffHeadsOnly(t *testing.T) {
},
expCfg: DeclarativeConfig{},
},
{
name: "HasDiff/EmptyChannel",
newCfg: DeclarativeConfig{
Packages: []Package{
{Schema: schemaPackage, Name: "foo", DefaultChannel: "stable"},
},
Channels: []Channel{
{Schema: schemaChannel, Name: "stable", Package: "foo", Entries: []ChannelEntry{
{Name: "foo.v0.2.0"},
}},
{Schema: schemaChannel, Name: "v1", Package: "foo", Entries: []ChannelEntry{
{Name: "foo.v0.1.0"},
}},
},
Bundles: []Bundle{
{
Schema: schemaBundle,
Name: "foo.v0.1.0",
Package: "foo",
Image: "reg/foo:latest",
Properties: []property.Property{
property.MustBuildPackage("foo", "0.1.0"),
},
},
{
Schema: schemaBundle,
Name: "foo.v0.2.0",
Package: "foo",
Image: "reg/foo:latest",
Properties: []property.Property{
property.MustBuildPackage("foo", "0.2.0"),
},
},
},
},
g: &DiffGenerator{
HeadsOnly: true,
Includer: DiffIncluder{
Packages: []DiffIncludePackage{
{
Name: "foo",
AllChannels: DiffIncludeChannel{
Versions: []semver.Version{semver.MustParse("0.2.0")},
},
},
},
},
},
expCfg: DeclarativeConfig{
Packages: []Package{
{Schema: schemaPackage, Name: "foo", DefaultChannel: "stable"},
},
Channels: []Channel{
{Schema: schemaChannel, Name: "stable", Package: "foo", Entries: []ChannelEntry{
{Name: "foo.v0.2.0"},
}},
},
Bundles: []Bundle{
{
Schema: schemaBundle,
Name: "foo.v0.2.0",
Package: "foo",
Image: "reg/foo:latest",
Properties: []property.Property{
property.MustBuildPackage("foo", "0.2.0"),
},
},
},
},
},
{
name: "HasDiff/OneBundle",
newCfg: DeclarativeConfig{
Expand Down

0 comments on commit d7a3c0b

Please sign in to comment.