Skip to content

Commit d7a3c0b

Browse files
authored
fix(diff): adds empty channel pruning with an include config on latest mode (#958)
Fixes #957 Signed-off-by: Jennifer Power <[email protected]>
1 parent 0b2f43f commit d7a3c0b

File tree

2 files changed

+150
-11
lines changed

2 files changed

+150
-11
lines changed

alpha/declcfg/diff.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -99,20 +99,19 @@ func (g *DiffGenerator) Run(oldModel, newModel model.Model) (model.Model, error)
9999
if err := latestPruneFromOutput(); err != nil {
100100
return nil, err
101101
}
102-
} else {
103-
for _, outputPkg := range outputModel {
104-
for _, ch := range outputPkg.Channels {
105-
if len(ch.Bundles) == 0 {
106-
delete(outputPkg.Channels, ch.Name)
107-
}
108-
}
109-
if len(outputPkg.Channels) == 0 {
110-
// Remove empty packages.
111-
delete(outputModel, outputPkg.Name)
102+
}
103+
104+
for _, outputPkg := range outputModel {
105+
for _, ch := range outputPkg.Channels {
106+
if len(ch.Bundles) == 0 {
107+
delete(outputPkg.Channels, ch.Name)
112108
}
113109
}
110+
if len(outputPkg.Channels) == 0 {
111+
// Remove empty packages.
112+
delete(outputModel, outputPkg.Name)
113+
}
114114
}
115-
116115
case isInclude: // Add included objects to outputModel.
117116

118117
// Assume heads-only is false for include additively since we already have the channel heads

alpha/declcfg/diff_test.go

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,76 @@ func TestDiffLatest(t *testing.T) {
130130
g: &DiffGenerator{},
131131
expCfg: DeclarativeConfig{},
132132
},
133+
{
134+
name: "HasDiff/EmptyChannel",
135+
oldCfg: DeclarativeConfig{},
136+
newCfg: DeclarativeConfig{
137+
Packages: []Package{
138+
{Schema: schemaPackage, Name: "foo", DefaultChannel: "stable"},
139+
},
140+
Channels: []Channel{
141+
{Schema: schemaChannel, Name: "stable", Package: "foo", Entries: []ChannelEntry{
142+
{Name: "foo.v0.2.0"},
143+
}},
144+
{Schema: schemaChannel, Name: "v1", Package: "foo", Entries: []ChannelEntry{
145+
{Name: "foo.v0.1.0"},
146+
}},
147+
},
148+
Bundles: []Bundle{
149+
{
150+
Schema: schemaBundle,
151+
Name: "foo.v0.1.0",
152+
Package: "foo",
153+
Image: "reg/foo:latest",
154+
Properties: []property.Property{
155+
property.MustBuildPackage("foo", "0.1.0"),
156+
},
157+
},
158+
{
159+
Schema: schemaBundle,
160+
Name: "foo.v0.2.0",
161+
Package: "foo",
162+
Image: "reg/foo:latest",
163+
Properties: []property.Property{
164+
property.MustBuildPackage("foo", "0.2.0"),
165+
},
166+
},
167+
},
168+
},
169+
g: &DiffGenerator{
170+
Includer: DiffIncluder{
171+
Packages: []DiffIncludePackage{
172+
{
173+
Name: "foo",
174+
AllChannels: DiffIncludeChannel{
175+
Versions: []semver.Version{semver.MustParse("0.2.0")},
176+
},
177+
},
178+
},
179+
},
180+
},
181+
expCfg: DeclarativeConfig{
182+
Packages: []Package{
183+
{Schema: schemaPackage, Name: "foo", DefaultChannel: "stable"},
184+
},
185+
Channels: []Channel{
186+
{Schema: schemaChannel, Name: "stable", Package: "foo", Entries: []ChannelEntry{
187+
{Name: "foo.v0.2.0"},
188+
}},
189+
},
190+
Bundles: []Bundle{
191+
{
192+
Schema: schemaBundle,
193+
Name: "foo.v0.2.0",
194+
Package: "foo",
195+
Image: "reg/foo:latest",
196+
Properties: []property.Property{
197+
property.MustBuildPackage("foo", "0.2.0"),
198+
},
199+
},
200+
},
201+
},
202+
},
133203
{
134204
name: "HasDiff/OneModifiedBundle",
135205
oldCfg: DeclarativeConfig{
@@ -1332,6 +1402,76 @@ func TestDiffHeadsOnly(t *testing.T) {
13321402
},
13331403
expCfg: DeclarativeConfig{},
13341404
},
1405+
{
1406+
name: "HasDiff/EmptyChannel",
1407+
newCfg: DeclarativeConfig{
1408+
Packages: []Package{
1409+
{Schema: schemaPackage, Name: "foo", DefaultChannel: "stable"},
1410+
},
1411+
Channels: []Channel{
1412+
{Schema: schemaChannel, Name: "stable", Package: "foo", Entries: []ChannelEntry{
1413+
{Name: "foo.v0.2.0"},
1414+
}},
1415+
{Schema: schemaChannel, Name: "v1", Package: "foo", Entries: []ChannelEntry{
1416+
{Name: "foo.v0.1.0"},
1417+
}},
1418+
},
1419+
Bundles: []Bundle{
1420+
{
1421+
Schema: schemaBundle,
1422+
Name: "foo.v0.1.0",
1423+
Package: "foo",
1424+
Image: "reg/foo:latest",
1425+
Properties: []property.Property{
1426+
property.MustBuildPackage("foo", "0.1.0"),
1427+
},
1428+
},
1429+
{
1430+
Schema: schemaBundle,
1431+
Name: "foo.v0.2.0",
1432+
Package: "foo",
1433+
Image: "reg/foo:latest",
1434+
Properties: []property.Property{
1435+
property.MustBuildPackage("foo", "0.2.0"),
1436+
},
1437+
},
1438+
},
1439+
},
1440+
g: &DiffGenerator{
1441+
HeadsOnly: true,
1442+
Includer: DiffIncluder{
1443+
Packages: []DiffIncludePackage{
1444+
{
1445+
Name: "foo",
1446+
AllChannels: DiffIncludeChannel{
1447+
Versions: []semver.Version{semver.MustParse("0.2.0")},
1448+
},
1449+
},
1450+
},
1451+
},
1452+
},
1453+
expCfg: DeclarativeConfig{
1454+
Packages: []Package{
1455+
{Schema: schemaPackage, Name: "foo", DefaultChannel: "stable"},
1456+
},
1457+
Channels: []Channel{
1458+
{Schema: schemaChannel, Name: "stable", Package: "foo", Entries: []ChannelEntry{
1459+
{Name: "foo.v0.2.0"},
1460+
}},
1461+
},
1462+
Bundles: []Bundle{
1463+
{
1464+
Schema: schemaBundle,
1465+
Name: "foo.v0.2.0",
1466+
Package: "foo",
1467+
Image: "reg/foo:latest",
1468+
Properties: []property.Property{
1469+
property.MustBuildPackage("foo", "0.2.0"),
1470+
},
1471+
},
1472+
},
1473+
},
1474+
},
13351475
{
13361476
name: "HasDiff/OneBundle",
13371477
newCfg: DeclarativeConfig{

0 commit comments

Comments
 (0)