Skip to content

Commit 3035450

Browse files
nicoonoclastekr
authored andcommitted
Make the test files deterministic (#2)
This patch was developed in binarydist's Debian package, to support the Reproducible Builds effort. https://reproducible-builds.org/
1 parent 9955b0a commit 3035450

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

common_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package binarydist
22

33
import (
4-
"crypto/rand"
54
"io"
65
"io/ioutil"
6+
"math/rand"
77
"os"
88
)
99

@@ -67,8 +67,9 @@ func fileCmp(a, b *os.File) int64 {
6767
return -1
6868
}
6969

70-
func mustWriteRandFile(path string, size int) *os.File {
70+
func mustWriteRandFile(path string, size int, seed int64) *os.File {
7171
p := make([]byte, size)
72+
rand.Seed(seed)
7273
_, err := rand.Read(p)
7374
if err != nil {
7475
panic(err)

diff_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ var diffT = []struct {
1313
new *os.File
1414
}{
1515
{
16-
old: mustWriteRandFile("test.old", 1e3),
17-
new: mustWriteRandFile("test.new", 1e3),
16+
old: mustWriteRandFile("test.old", 1e3, 1),
17+
new: mustWriteRandFile("test.new", 1e3, 2),
1818
},
1919
{
2020
old: mustOpen("testdata/sample.old"),

patch_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import (
88
)
99

1010
func TestPatch(t *testing.T) {
11-
mustWriteRandFile("test.old", 1e3)
12-
mustWriteRandFile("test.new", 1e3)
11+
mustWriteRandFile("test.old", 1e3, 1)
12+
mustWriteRandFile("test.new", 1e3, 2)
1313

1414
got, err := ioutil.TempFile("/tmp", "bspatch.")
1515
if err != nil {

0 commit comments

Comments
 (0)