Skip to content
This repository was archived by the owner on Mar 27, 2024. It is now read-only.

Commit 9e5ece6

Browse files
committed
Fixed equality check in package comparison
1 parent 8f5300e commit 9e5ece6

File tree

3 files changed

+12
-36
lines changed

3 files changed

+12
-36
lines changed

tests/multi_diff_expected.json

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -115,36 +115,6 @@
115115
"Size": 73348
116116
}
117117
]
118-
},
119-
{
120-
"Package": "setuptools",
121-
"Info1": [
122-
{
123-
"Version": "36.2.2",
124-
"Size": 839895
125-
}
126-
],
127-
"Info2": [
128-
{
129-
"Version": "36.2.2",
130-
"Size": 1157078
131-
}
132-
]
133-
},
134-
{
135-
"Package": "wheel",
136-
"Info1": [
137-
{
138-
"Version": "0.29.0",
139-
"Size": 103509
140-
}
141-
],
142-
"Info2": [
143-
{
144-
"Version": "0.29.0",
145-
"Size": 137451
146-
}
147-
]
148118
}
149119
]
150120
}

utils/package_diff_utils.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,29 +129,36 @@ func diffMaps(map1, map2 interface{}) interface{} {
129129
for _, pack := range map1Value.MapKeys() {
130130
packageEntry1 := map1Value.MapIndex(pack)
131131
packageEntry2 := map2Value.MapIndex(pack)
132+
// If the package does not exist in Image2's map of packages, add it to the collection of unique packages in Image1
132133
if !packageEntry2.IsValid() {
133134
diff1.SetMapIndex(pack, packageEntry1)
135+
// If the package exists in Image2's map of packages but the package information differs between images, add it to
136+
// the difference. Otherwise, if the information is consistent across images, delete it from the Image2's map of packages.
134137
} else {
135138
if multiV {
136139
if !reflect.DeepEqual(packageEntry2.Interface(), packageEntry1.Interface()) {
137140
multiInfoDiff = multiVersionDiff(multiInfoDiff, pack.String(),
138-
packageEntry1.Interface().(map[string]PackageInfo),
139-
packageEntry2.Interface().(map[string]PackageInfo))
141+
packageEntry1.Interface().(map[string]PackageInfo),
142+
packageEntry2.Interface().(map[string]PackageInfo))
140143
}
141144
} else {
142145
packageInfo1 := packageEntry1.Interface().(PackageInfo)
143146
packageInfo2 := packageEntry2.Interface().(PackageInfo)
144-
if packageInfo2.Version != packageInfo2.Version {
147+
// If two instances of the same package don't have the same version, then they are considered to be different
148+
if packageInfo1.Version != packageInfo2.Version {
145149
infoDiff = append(infoDiff, Info{pack.String(), packageInfo1, packageInfo2})
146150
}
147151
}
148152
map2Value.SetMapIndex(pack, reflect.Value{})
149153
}
150154
}
155+
156+
// The packages remaining in Image2's map of images are those that exist uniquely in Image2
151157
for _, key2 := range map2Value.MapKeys() {
152158
packageEntry2 := map2Value.MapIndex(key2)
153159
diff2.SetMapIndex(key2, packageEntry2)
154160
}
161+
155162
if multiV {
156163
return MultiVersionPackageDiff{Packages1: diff1.Interface().(map[string]map[string]PackageInfo),
157164
Packages2: diff2.Interface().(map[string]map[string]PackageInfo), InfoDiff: multiInfoDiff}

utils/package_diff_utils_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ func TestDiffMaps(t *testing.T) {
6060
Packages1: map[string]PackageInfo{},
6161
Packages2: map[string]PackageInfo{},
6262
InfoDiff: []Info{
63-
{"pac2", PackageInfo{"2.0", 50}, PackageInfo{"2.0", 45}},
6463
{"pac3", PackageInfo{"3.0", 60}, PackageInfo{"4.0", 60}}},
6564
},
6665
},
@@ -141,7 +140,7 @@ func TestDiffMaps(t *testing.T) {
141140
sort.Sort(ByPackage(expected.InfoDiff))
142141
sort.Sort(ByPackage(actual.InfoDiff))
143142
if !reflect.DeepEqual(expected, actual) {
144-
t.Errorf("expected Diff to be: %s but got:%s", expected, actual)
143+
t.Errorf("expected Diff to be: %v but got:%v", expected, actual)
145144
return
146145
}
147146
case MultiVersionPackageDiff:
@@ -158,7 +157,7 @@ func TestDiffMaps(t *testing.T) {
158157
sort.Sort(ByPackageInfo(pack2.Info2))
159158
}
160159
if !reflect.DeepEqual(expected, actual) {
161-
t.Errorf("expected Diff to be: %s but got:%s", expected, actual)
160+
t.Errorf("expected Diff to be: %v but got:%v", expected, actual)
162161
return
163162
}
164163
}

0 commit comments

Comments
 (0)