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

Commit 773aca0

Browse files
authored
Merge pull request #38 from cftorres/InfoDiffFix
Fixing package diff check
2 parents a5a8fc9 + 9e5ece6 commit 773aca0

File tree

3 files changed

+23
-41
lines changed

3 files changed

+23
-41
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: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ func multiVersionDiff(infoDiff []MultiVersionInfo, packageName string, map1, map
5252
diff1 = append(diff1, packInfo1)
5353
continue
5454
} else {
55-
if reflect.DeepEqual(packInfo1, packInfo2) {
55+
// If a package instance is installed in the same place in Image1 and Image2 with the same version,
56+
// then they are the same package and should not be included in the diff
57+
if packInfo1.Version == packInfo2.Version {
5658
delete(map2, path)
5759
} else {
5860
diff1 = append(diff1, packInfo1)
@@ -127,25 +129,36 @@ func diffMaps(map1, map2 interface{}) interface{} {
127129
for _, pack := range map1Value.MapKeys() {
128130
packageEntry1 := map1Value.MapIndex(pack)
129131
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
130133
if !packageEntry2.IsValid() {
131134
diff1.SetMapIndex(pack, packageEntry1)
132-
} else if !reflect.DeepEqual(packageEntry2.Interface(), packageEntry1.Interface()) {
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.
137+
} else {
133138
if multiV {
134-
multiInfoDiff = multiVersionDiff(multiInfoDiff, pack.String(),
135-
packageEntry1.Interface().(map[string]PackageInfo), packageEntry2.Interface().(map[string]PackageInfo))
139+
if !reflect.DeepEqual(packageEntry2.Interface(), packageEntry1.Interface()) {
140+
multiInfoDiff = multiVersionDiff(multiInfoDiff, pack.String(),
141+
packageEntry1.Interface().(map[string]PackageInfo),
142+
packageEntry2.Interface().(map[string]PackageInfo))
143+
}
136144
} else {
137-
infoDiff = append(infoDiff, Info{pack.String(), packageEntry1.Interface().(PackageInfo),
138-
packageEntry2.Interface().(PackageInfo)})
145+
packageInfo1 := packageEntry1.Interface().(PackageInfo)
146+
packageInfo2 := packageEntry2.Interface().(PackageInfo)
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 {
149+
infoDiff = append(infoDiff, Info{pack.String(), packageInfo1, packageInfo2})
150+
}
139151
}
140152
map2Value.SetMapIndex(pack, reflect.Value{})
141-
} else {
142-
map2Value.SetMapIndex(pack, reflect.Value{})
143153
}
144154
}
155+
156+
// The packages remaining in Image2's map of images are those that exist uniquely in Image2
145157
for _, key2 := range map2Value.MapKeys() {
146158
packageEntry2 := map2Value.MapIndex(key2)
147159
diff2.SetMapIndex(key2, packageEntry2)
148160
}
161+
149162
if multiV {
150163
return MultiVersionPackageDiff{Packages1: diff1.Interface().(map[string]map[string]PackageInfo),
151164
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)