mirror of
https://github.com/priyanshujain/sanderling.git
synced 2026-10-04 12:07:09 +00:00
test(sidecarassets): assert reuse via sentinel bytes not mtime
This commit is contained in:
1 parent
c576462b7a
commit
a74fa46221
1 file changed
+7
-6
@@ -3,6 +3,7 @@
|
|||||||
package sidecarassets
|
package sidecarassets
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"os"
|
"os"
|
||||||
@@ -54,21 +55,21 @@ func TestExtract_ReusesIdenticalFile(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
originalStat, err := os.Stat(path)
|
sentinel := []byte("SENTINEL-do-not-rewrite")
|
||||||
if err != nil {
|
if err := os.WriteFile(path, sentinel, 0o644); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
originalModTime := originalStat.ModTime()
|
|
||||||
|
|
||||||
if _, err := Extract(directory); err != nil {
|
if _, err := Extract(directory); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
secondStat, err := os.Stat(path)
|
|
||||||
|
after, err := os.ReadFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if !secondStat.ModTime().Equal(originalModTime) {
|
if !bytes.Equal(after, sentinel) {
|
||||||
t.Errorf("second extract should not have rewritten the file")
|
t.Errorf("second extract rewrote the existing JAR; reuse branch corrupted on-disk file")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user