Skip to content

Commit d7f1648

Browse files
committed
handle potential error returned by io.WriteString
1 parent 5370aec commit d7f1648

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

hash_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,13 @@ func TestCreateFileHash(t *testing.T) {
3131
contentFile.Close()
3232

3333
h := md5.New()
34-
io.WriteString(h, content)
34+
n, err := io.WriteString(h, content)
35+
if err != nil {
36+
t.Error(err)
37+
}
38+
if n != len(content) {
39+
t.Errorf("not all bytes are written, expected to write %d bytes, written: %d", len(content), n)
40+
}
3541
expectedContentHash := hex.EncodeToString(h.Sum(nil))
3642

3743
emptyHash := md5.New()

process_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,13 @@ func TestGroupByHash(t *testing.T) {
4343
}
4444

4545
h := md5.New()
46-
io.WriteString(h, f.text)
46+
n, err = io.WriteString(h, f.text)
47+
if err != nil {
48+
t.Error(err)
49+
}
50+
if n != len(f.text) {
51+
t.Errorf("not all bytes are written, expected to write %d bytes, written: %d", len(f.text), n)
52+
}
4753
f.hash = hex.EncodeToString(h.Sum(nil))
4854
}
4955

0 commit comments

Comments
 (0)