Skip to content

Commit

Permalink
Cleanup error handling in orderer/common/bootstrap
Browse files Browse the repository at this point in the history
Replace create/write/close with ioutil.WriteFile and error check.

Signed-off-by: Matthew Sykes <sykesmat@us.ibm.com>
  • Loading branch information
sykesm authored and Brett Logan committed May 23, 2020
1 parent 8b0c0e4 commit 7fde3f6
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions orderer/common/bootstrap/file/bootstrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,8 @@ func TestGenesisBlock(t *testing.T) {
})

t.Run("Bad - Malformed Block", func(t *testing.T) {
testFileHandle, err := os.Create(testFile)
err := ioutil.WriteFile(testFile, []byte("abc"), 0644)
assert.NoErrorf(t, err, "generate temporary test file: %s", file)
defer os.Remove(testFile)
testFileHandle.Write([]byte("abc"))
testFileHandle.Close()

assert.Panics(t, func() {
helper := bootfile.New(testFile)
Expand Down Expand Up @@ -74,11 +71,9 @@ func TestGenesisBlock(t *testing.T) {
Metadata: metadata,
}
marshalledBlock, _ := proto.Marshal(block)
testFileHandle, err := os.Create(testFile)
err := ioutil.WriteFile(testFile, marshalledBlock, 0644)
assert.NoErrorf(t, err, "generate temporary test file: %s", file)
defer os.Remove(testFile)
testFileHandle.Write(marshalledBlock)
testFileHandle.Close()

helper := bootfile.New(testFile)
outBlock := helper.GenesisBlock()
Expand Down Expand Up @@ -126,12 +121,9 @@ func TestReplaceGenesisBlockFile(t *testing.T) {
defer os.RemoveAll(testDir)

testFile := path.Join(testDir, file)
testFileHandle, err := os.Create(testFile)
err = ioutil.WriteFile(testFile, marshalledBlock, 0644)
assert.NoErrorf(t, err, "generate temporary test file: %s", file)

testFileHandle.Write(marshalledBlock)
testFileHandle.Close()

testFileBak := path.Join(testDir, fileBak)
testFileFake := path.Join(testDir, fileFake)

Expand Down

0 comments on commit 7fde3f6

Please sign in to comment.