Skip to content

Commit 2e6f282

Browse files
refactor: simplify error logic for writing file
1 parent 855fcec commit 2e6f282

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

internal/bootstrap/deployer_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -378,10 +378,11 @@ description: Juju controller
378378
f, err := os.OpenFile(path, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
379379
c.Assert(err, jc.ErrorIsNil)
380380

381+
defer f.Close()
382+
381383
size, err := f.Write(buf.Bytes())
382-
if err1 := f.Close(); err1 != nil && err == nil {
383-
err = err1
384-
}
384+
c.Assert(err, jc.ErrorIsNil)
385+
err = f.Close()
385386
c.Assert(err, jc.ErrorIsNil)
386387

387388
return path, int64(size)

0 commit comments

Comments
 (0)