Commit c97f9dd
authored
Make diff result as deterministic as possible (#231)
`helm diff upgrade` output is non-deterministic, due to that it shows diff entry in the order of the Go map objects containing source/target manifests to be compared.
The non-determinism makes writing integration test with something and helm-diff harder, as snapshot testing is impossible.
This patch fixes it by enhancing the diff logic to sort those map keys in alphabetical order and use the result for iterating map entries.
Note that you can use the below snippet for non-scientific testing to verify that the result is (seemingly) deterministic now:
```
for (( i=0; i<10; ++i)); do helm --debug diff upgrade --dry-run foo stable/prometheus-operator | sha256sum ; done
```
Before this change it should print output like:
```
$ for (( i=0; i<10; ++i)); do helm --debug diff upgrade --dry-run foo stable/prometheus-operator | sha256sum ; done
754f01763544baeb4f405ccdcdf7ffd9075bfddf9777a993f1e787ea6096b0b4 -
88a5f76e3802e0e4693fe007d4ae6fc8c3ae5cf97b7244dc67e45a282385e2c3 -
b57e66a22c49ec2a29dacc9e912a313aca85b403ac3d2960fc0afddeda544a77 -
769c605ea8c13f4251559948260f8c6104d821ce79de1367d2a6ee477be37777 -
afce52fa595beaf106303ae162efb4f31a7336c84a630b1d4ea1e59ba1468292 -
12a3b3c1e3fdcd0b4b62517583135abe20249d69e6c4aed9acfab7c999771bdd -
294d5db8edec946737036014b549baa93601aadf430f1b80517db9eca2dd1330 -
31860127c9ae69e5d0154b60cc7ea05e992bac54e1453c88198940e719552f72 -
dce05e1932ca7d6e15416de3b0a891ae68e3c885247f683fe50068b2c551213b -
f0101d6e952fd0344d9e45518254cb3e0692156becaae106fcc7b1dae273ac04 -
```
After the change it should be like:
```
$ make build install/helm3
$ for (( i=0; i<10; ++i)); do helm --debug diff upgrade --dry-run foo stable/prometheus-operator | sha256sum ; done
ee4e79f6adee9e2606c9d855949afd39cf5a13a650cb55a3d74184c7edaf956d -
ee4e79f6adee9e2606c9d855949afd39cf5a13a650cb55a3d74184c7edaf956d -
ee4e79f6adee9e2606c9d855949afd39cf5a13a650cb55a3d74184c7edaf956d -
ee4e79f6adee9e2606c9d855949afd39cf5a13a650cb55a3d74184c7edaf956d -
ee4e79f6adee9e2606c9d855949afd39cf5a13a650cb55a3d74184c7edaf956d -
ee4e79f6adee9e2606c9d855949afd39cf5a13a650cb55a3d74184c7edaf956d -
ee4e79f6adee9e2606c9d855949afd39cf5a13a650cb55a3d74184c7edaf956d -
ee4e79f6adee9e2606c9d855949afd39cf5a13a650cb55a3d74184c7edaf956d -
ee4e79f6adee9e2606c9d855949afd39cf5a13a650cb55a3d74184c7edaf956d -
ee4e79f6adee9e2606c9d855949afd39cf5a13a650cb55a3d74184c7edaf956d -
```1 parent 312d45a commit c97f9dd
1 file changed
+18
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
26 | | - | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
27 | 29 | | |
28 | 30 | | |
29 | 31 | | |
| |||
51 | 53 | | |
52 | 54 | | |
53 | 55 | | |
54 | | - | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
55 | 59 | | |
56 | 60 | | |
57 | 61 | | |
| |||
262 | 266 | | |
263 | 267 | | |
264 | 268 | | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
0 commit comments