cli: use ioutil instead of os to read/write files
Go 1.15 doesn't have os.ReadFile and os.WiteFile.
This commit is contained in:
parent
4ea0aef9d5
commit
ba49209d8a
4 changed files with 13 additions and 13 deletions
|
@ -370,7 +370,7 @@ func TestContractManifestGroups(t *testing.T) {
|
||||||
})
|
})
|
||||||
t.Run("corrupted NEF file", func(t *testing.T) {
|
t.Run("corrupted NEF file", func(t *testing.T) {
|
||||||
f := filepath.Join(tmpDir, "invalid.nef")
|
f := filepath.Join(tmpDir, "invalid.nef")
|
||||||
require.NoError(t, os.WriteFile(f, []byte{1, 2, 3}, os.ModePerm))
|
require.NoError(t, ioutil.WriteFile(f, []byte{1, 2, 3}, os.ModePerm))
|
||||||
e.RunWithError(t, "neo-go", "contract", "manifest", "add-group",
|
e.RunWithError(t, "neo-go", "contract", "manifest", "add-group",
|
||||||
"--wallet", testWalletPath, "--account", testWalletAccount,
|
"--wallet", testWalletPath, "--account", testWalletAccount,
|
||||||
"--sender", testWalletAccount, "--nef", f)
|
"--sender", testWalletAccount, "--nef", f)
|
||||||
|
@ -383,7 +383,7 @@ func TestContractManifestGroups(t *testing.T) {
|
||||||
})
|
})
|
||||||
t.Run("corrupted manifest file", func(t *testing.T) {
|
t.Run("corrupted manifest file", func(t *testing.T) {
|
||||||
f := filepath.Join(tmpDir, "invalid.manifest.json")
|
f := filepath.Join(tmpDir, "invalid.manifest.json")
|
||||||
require.NoError(t, os.WriteFile(f, []byte{1, 2, 3}, os.ModePerm))
|
require.NoError(t, ioutil.WriteFile(f, []byte{1, 2, 3}, os.ModePerm))
|
||||||
e.RunWithError(t, "neo-go", "contract", "manifest", "add-group",
|
e.RunWithError(t, "neo-go", "contract", "manifest", "add-group",
|
||||||
"--wallet", testWalletPath, "--account", testWalletAccount,
|
"--wallet", testWalletPath, "--account", testWalletAccount,
|
||||||
"--sender", testWalletAccount, "--nef", nefName,
|
"--sender", testWalletAccount, "--nef", nefName,
|
||||||
|
|
|
@ -61,7 +61,7 @@ func TestDBRestoreDump(t *testing.T) {
|
||||||
t.Run("bad logger config", func(t *testing.T) {
|
t.Run("bad logger config", func(t *testing.T) {
|
||||||
badConfigDir := t.TempDir()
|
badConfigDir := t.TempDir()
|
||||||
logfile := filepath.Join(badConfigDir, "logdir")
|
logfile := filepath.Join(badConfigDir, "logdir")
|
||||||
require.NoError(t, os.WriteFile(logfile, []byte{1, 2, 3}, os.ModePerm))
|
require.NoError(t, ioutil.WriteFile(logfile, []byte{1, 2, 3}, os.ModePerm))
|
||||||
cfg = loadConfig(t)
|
cfg = loadConfig(t)
|
||||||
cfg.ApplicationConfiguration.LogPath = filepath.Join(logfile, "file.log")
|
cfg.ApplicationConfiguration.LogPath = filepath.Join(logfile, "file.log")
|
||||||
out, err = yaml.Marshal(cfg)
|
out, err = yaml.Marshal(cfg)
|
||||||
|
@ -76,7 +76,7 @@ func TestDBRestoreDump(t *testing.T) {
|
||||||
t.Run("bad storage config", func(t *testing.T) {
|
t.Run("bad storage config", func(t *testing.T) {
|
||||||
badConfigDir := t.TempDir()
|
badConfigDir := t.TempDir()
|
||||||
logfile := filepath.Join(badConfigDir, "logdir")
|
logfile := filepath.Join(badConfigDir, "logdir")
|
||||||
require.NoError(t, os.WriteFile(logfile, []byte{1, 2, 3}, os.ModePerm))
|
require.NoError(t, ioutil.WriteFile(logfile, []byte{1, 2, 3}, os.ModePerm))
|
||||||
cfg = loadConfig(t)
|
cfg = loadConfig(t)
|
||||||
cfg.ApplicationConfiguration.DBConfiguration.Type = ""
|
cfg.ApplicationConfiguration.DBConfiguration.Type = ""
|
||||||
out, err = yaml.Marshal(cfg)
|
out, err = yaml.Marshal(cfg)
|
||||||
|
|
|
@ -47,7 +47,7 @@ func TestHandleLoggingParams(t *testing.T) {
|
||||||
|
|
||||||
t.Run("logdir is a file", func(t *testing.T) {
|
t.Run("logdir is a file", func(t *testing.T) {
|
||||||
logfile := filepath.Join(d, "logdir")
|
logfile := filepath.Join(d, "logdir")
|
||||||
require.NoError(t, os.WriteFile(logfile, []byte{1, 2, 3}, os.ModePerm))
|
require.NoError(t, ioutil.WriteFile(logfile, []byte{1, 2, 3}, os.ModePerm))
|
||||||
set := flag.NewFlagSet("flagSet", flag.ExitOnError)
|
set := flag.NewFlagSet("flagSet", flag.ExitOnError)
|
||||||
ctx := cli.NewContext(cli.NewApp(), set, nil)
|
ctx := cli.NewContext(cli.NewApp(), set, nil)
|
||||||
cfg := config.ApplicationConfiguration{
|
cfg := config.ApplicationConfiguration{
|
||||||
|
@ -181,7 +181,7 @@ func TestRestoreDB(t *testing.T) {
|
||||||
t.Run("invalid logger path", func(t *testing.T) {
|
t.Run("invalid logger path", func(t *testing.T) {
|
||||||
badCfgDir := t.TempDir()
|
badCfgDir := t.TempDir()
|
||||||
logfile := filepath.Join(badCfgDir, "logdir")
|
logfile := filepath.Join(badCfgDir, "logdir")
|
||||||
require.NoError(t, os.WriteFile(logfile, []byte{1, 2, 3}, os.ModePerm))
|
require.NoError(t, ioutil.WriteFile(logfile, []byte{1, 2, 3}, os.ModePerm))
|
||||||
cfg, err := config.LoadFile(filepath.Join(goodCfg, "protocol.privnet.yml"))
|
cfg, err := config.LoadFile(filepath.Join(goodCfg, "protocol.privnet.yml"))
|
||||||
require.NoError(t, err, "could not load config")
|
require.NoError(t, err, "could not load config")
|
||||||
cfg.ApplicationConfiguration.LogPath = filepath.Join(logfile, "file.log")
|
cfg.ApplicationConfiguration.LogPath = filepath.Join(logfile, "file.log")
|
||||||
|
@ -223,7 +223,7 @@ func TestRestoreDB(t *testing.T) {
|
||||||
})
|
})
|
||||||
t.Run("corrupted in: invalid block count", func(t *testing.T) {
|
t.Run("corrupted in: invalid block count", func(t *testing.T) {
|
||||||
inPath := filepath.Join(t.TempDir(), "file3.acc")
|
inPath := filepath.Join(t.TempDir(), "file3.acc")
|
||||||
require.NoError(t, os.WriteFile(inPath, []byte{1, 2, 3}, // file is expected to start from uint32
|
require.NoError(t, ioutil.WriteFile(inPath, []byte{1, 2, 3}, // file is expected to start from uint32
|
||||||
os.ModePerm))
|
os.ModePerm))
|
||||||
*in = inPath
|
*in = inPath
|
||||||
require.Error(t, restoreDB(ctx))
|
require.Error(t, restoreDB(ctx))
|
||||||
|
@ -232,10 +232,10 @@ func TestRestoreDB(t *testing.T) {
|
||||||
})
|
})
|
||||||
t.Run("corrupted in: corrupted block", func(t *testing.T) {
|
t.Run("corrupted in: corrupted block", func(t *testing.T) {
|
||||||
inPath := filepath.Join(t.TempDir(), "file3.acc")
|
inPath := filepath.Join(t.TempDir(), "file3.acc")
|
||||||
b, err := os.ReadFile(testDump)
|
b, err := ioutil.ReadFile(testDump)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
b[5] = 0xff // file is expected to start from uint32 (4 bytes) followed by the first block, so corrupt the first block bytes
|
b[5] = 0xff // file is expected to start from uint32 (4 bytes) followed by the first block, so corrupt the first block bytes
|
||||||
require.NoError(t, os.WriteFile(inPath, b, os.ModePerm))
|
require.NoError(t, ioutil.WriteFile(inPath, b, os.ModePerm))
|
||||||
*in = inPath
|
*in = inPath
|
||||||
require.Error(t, restoreDB(ctx))
|
require.Error(t, restoreDB(ctx))
|
||||||
|
|
||||||
|
@ -243,12 +243,12 @@ func TestRestoreDB(t *testing.T) {
|
||||||
})
|
})
|
||||||
t.Run("incremental dump", func(t *testing.T) {
|
t.Run("incremental dump", func(t *testing.T) {
|
||||||
inPath := filepath.Join(t.TempDir(), "file1_incremental.acc")
|
inPath := filepath.Join(t.TempDir(), "file1_incremental.acc")
|
||||||
b, err := os.ReadFile(testDump)
|
b, err := ioutil.ReadFile(testDump)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
start := make([]byte, 4)
|
start := make([]byte, 4)
|
||||||
t.Run("good", func(t *testing.T) {
|
t.Run("good", func(t *testing.T) {
|
||||||
binary.LittleEndian.PutUint32(start, 1) // start from the first block
|
binary.LittleEndian.PutUint32(start, 1) // start from the first block
|
||||||
require.NoError(t, os.WriteFile(inPath, append(start, b...),
|
require.NoError(t, ioutil.WriteFile(inPath, append(start, b...),
|
||||||
os.ModePerm))
|
os.ModePerm))
|
||||||
*in = inPath
|
*in = inPath
|
||||||
*incremental = true
|
*incremental = true
|
||||||
|
@ -257,7 +257,7 @@ func TestRestoreDB(t *testing.T) {
|
||||||
})
|
})
|
||||||
t.Run("dump is too high", func(t *testing.T) {
|
t.Run("dump is too high", func(t *testing.T) {
|
||||||
binary.LittleEndian.PutUint32(start, 2) // start from the second block
|
binary.LittleEndian.PutUint32(start, 2) // start from the second block
|
||||||
require.NoError(t, os.WriteFile(inPath, append(start, b...),
|
require.NoError(t, ioutil.WriteFile(inPath, append(start, b...),
|
||||||
os.ModePerm))
|
os.ModePerm))
|
||||||
*in = inPath
|
*in = inPath
|
||||||
*incremental = true
|
*incremental = true
|
||||||
|
|
|
@ -47,7 +47,7 @@ func TestServerStart(t *testing.T) {
|
||||||
t.Run("bad logger config", func(t *testing.T) {
|
t.Run("bad logger config", func(t *testing.T) {
|
||||||
badConfigDir := t.TempDir()
|
badConfigDir := t.TempDir()
|
||||||
logfile := filepath.Join(badConfigDir, "logdir")
|
logfile := filepath.Join(badConfigDir, "logdir")
|
||||||
require.NoError(t, os.WriteFile(logfile, []byte{1, 2, 3}, os.ModePerm))
|
require.NoError(t, ioutil.WriteFile(logfile, []byte{1, 2, 3}, os.ModePerm))
|
||||||
saveCfg(t, func(cfg *config.Config) {
|
saveCfg(t, func(cfg *config.Config) {
|
||||||
cfg.ApplicationConfiguration.LogPath = filepath.Join(logfile, "file.log")
|
cfg.ApplicationConfiguration.LogPath = filepath.Join(logfile, "file.log")
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue