Skip to content
Prev Previous commit
Next Next commit
fix: oldEssentialToV3
  • Loading branch information
lczyk committed Feb 26, 2026
commit ff5ac9e20df4c988769e5a1ea60eda268e26f5f7
14 changes: 12 additions & 2 deletions internal/setup/setup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4227,7 +4227,9 @@ func oldEssentialToV3(c *C, input []byte) (out string, skip bool) {
for _, rawSlice := range slices {
if slice, ok := rawSlice.(map[string]any); ok {
newEssential := make(map[string]any)
sliceEssentialProcessed := false
if oldEssential, ok := slice["essential"].([]any); ok {
sliceEssentialProcessed = true
for _, value := range oldEssential {
s := value.(string)
if _, ok := newEssential[s]; ok {
Expand All @@ -4238,6 +4240,7 @@ func oldEssentialToV3(c *C, input []byte) (out string, skip bool) {
}
}
if oldEssential, ok := slice["v3-essential"].(map[string]any); ok {
sliceEssentialProcessed = true
for key, value := range oldEssential {
if _, ok := newEssential[key]; ok {
return "", true
Expand All @@ -4246,13 +4249,17 @@ func oldEssentialToV3(c *C, input []byte) (out string, skip bool) {
}
delete(slice, "v3-essential")
}
slice["essential"] = newEssential
if sliceEssentialProcessed {
slice["essential"] = newEssential
}
}
}
}

newEssential := make(map[string]any)
essentialProcessed := false
if oldEssential, ok := raw["essential"].([]any); ok {
essentialProcessed = true
for _, item := range oldEssential {
s := item.(string)
if _, ok := newEssential[s]; ok {
Expand All @@ -4263,6 +4270,7 @@ func oldEssentialToV3(c *C, input []byte) (out string, skip bool) {
}
}
if oldEssential, ok := raw["v3-essential"].(map[string]any); ok {
essentialProcessed = true
for key, value := range oldEssential {
if _, ok := newEssential[key]; ok {
// Duplicated entries are impossible in v3.
Expand All @@ -4272,7 +4280,9 @@ func oldEssentialToV3(c *C, input []byte) (out string, skip bool) {
}
delete(raw, "v3-essential")
}
raw["essential"] = newEssential
if essentialProcessed {
raw["essential"] = newEssential
}

bs, err := yaml.Marshal(raw)
c.Assert(err, IsNil)
Expand Down
Loading