libs/os: remove unused aliases, add test cases (#5654)

Remove unused ReadFile (unused) and
WriteFile (almost unused, alias of ioutil.WriteFile).

Add testcases for Must{Read,Write}File.
This commit is contained in:
Alessio Treglia
2020-11-13 10:59:45 +00:00
committed by GitHub
parent 95cff1efb4
commit 8bd3d5105f
9 changed files with 71 additions and 85 deletions
+11 -4
View File
@@ -4,6 +4,7 @@ import (
"bytes"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
"text/template"
@@ -63,7 +64,7 @@ func WriteConfigFile(configFilePath string, config *Config) {
panic(err)
}
tmos.MustWriteFile(configFilePath, buffer.Bytes(), 0644)
mustWriteFile(configFilePath, buffer.Bytes(), 0644)
}
// Note: any changes to the comments/variables/mapstructure
@@ -492,16 +493,22 @@ func ResetTestRootWithChainID(testName string, chainID string) *Config {
chainID = "tendermint_test"
}
testGenesis := fmt.Sprintf(testGenesisFmt, chainID)
tmos.MustWriteFile(genesisFilePath, []byte(testGenesis), 0644)
mustWriteFile(genesisFilePath, []byte(testGenesis), 0644)
}
// we always overwrite the priv val
tmos.MustWriteFile(privKeyFilePath, []byte(testPrivValidatorKey), 0644)
tmos.MustWriteFile(privStateFilePath, []byte(testPrivValidatorState), 0644)
mustWriteFile(privKeyFilePath, []byte(testPrivValidatorKey), 0644)
mustWriteFile(privStateFilePath, []byte(testPrivValidatorState), 0644)
config := TestConfig().SetRoot(rootDir)
return config
}
func mustWriteFile(filePath string, contents []byte, mode os.FileMode) {
if err := ioutil.WriteFile(filePath, contents, mode); err != nil {
tmos.Exit(fmt.Sprintf("failed to write file: %v", err))
}
}
var testGenesisFmt = `{
"genesis_time": "2018-10-10T08:20:13.695936996Z",
"chain_id": "%s",