Skip to content
Merged
Show file tree
Hide file tree
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
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