Skip to content

Commit

Permalink
cleanup os/ioutil.ReadFile, ...
Browse files Browse the repository at this point in the history
  • Loading branch information
hedzr committed May 1, 2022
1 parent 73a64c6 commit c4b8827
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
12 changes: 6 additions & 6 deletions base_opt_test.go
Expand Up @@ -258,7 +258,7 @@ func TestTomlLoad(t *testing.T) {
meta toml.MetaData
)

if err = os.WriteFile(".tmp.toml", tomlSample, 0o600); err != nil {
if err = dir.WriteFile(".tmp.toml", tomlSample, 0o600); err != nil {
t.Fatal(err)
}

Expand Down Expand Up @@ -313,7 +313,7 @@ func TestConfigFiles(t *testing.T) {
t.Fatal(err)
}

_ = os.WriteFile(".tmp.yaml", []byte(`
_ = dir.WriteFile(".tmp.yaml", []byte(`
app'x':"
`), 0o600)

Expand All @@ -323,19 +323,19 @@ app'x':"
}
_ = os.Remove(".tmp.yaml")

_ = os.WriteFile(".tmp.json", []byte(`{"app":{"debug":errrrr}}`), 0o600)
_ = dir.WriteFile(".tmp.json", []byte(`{"app":{"debug":errrrr}}`), 0o600)
if _, _, err = cmdr.LoadConfigFile(".tmp.json"); err == nil {
t.Fatal(err)
}

_ = os.WriteFile(".tmp.json", []byte(`{"app":{"debug":false}}`), 0o600)
_ = dir.WriteFile(".tmp.json", []byte(`{"app":{"debug":false}}`), 0o600)
// try loading cfg again for gocov
if _, _, err = cmdr.LoadConfigFile(".tmp.json"); err != nil {
t.Fatal(err)
}
_ = os.Remove(".tmp.json")

_ = os.WriteFile(".tmp.toml", []byte(`
_ = dir.WriteFile(".tmp.toml", []byte(`
runmode=devel
`), 0o600)
if _, _, err = cmdr.LoadConfigFile(".tmp.toml"); err == nil {
Expand All @@ -344,7 +344,7 @@ runmode=devel

_, _, _ = cmdr.LoadConfigFile(".tmp.x.toml") //nolint:dogsled //keep it

_ = os.WriteFile(".tmp.toml", []byte(`
_ = dir.WriteFile(".tmp.toml", []byte(`
runmode="devel"
[app]
debug=true
Expand Down
10 changes: 5 additions & 5 deletions helpers_test.go
Expand Up @@ -64,7 +64,7 @@ func (s *cfgLoaded) OnConfigReloaded() {
func cfg(t *testing.T, clcl cmdr.ConfigReloaded) {
cmdr.AddOnConfigLoadedListener(clcl)

_ = os.WriteFile(".tmp.yaml", []byte(`
_ = dir.WriteFile(".tmp.yaml", []byte(`
app:
debug: false
ms:
Expand Down Expand Up @@ -127,7 +127,7 @@ app:
`), 0o600)
_ = dir.EnsureDir("conf.d")

_ = os.WriteFile("conf.d/tmp.yaml", []byte(`
_ = dir.WriteFile("conf.d/tmp.yaml", []byte(`
app:
debug: false
ms:
Expand All @@ -143,16 +143,16 @@ app:

t.Logf("%v, %v", cmdr.GetUsedConfigFile(), cmdr.GetUsedConfigSubDir())
t.Logf("%v, %v", cmdr.CurrentOptions(), cmdr.GetUsingConfigFiles())
_ = os.WriteFile("conf.d/tmp.yaml", []byte(`
_ = dir.WriteFile("conf.d/tmp.yaml", []byte(`
app:
debug: true
ms:
tags:
modify:
wed: [3, 4]
`), 0o600)
_ = os.WriteFile("conf.d/tmp.json", []byte(`{"app":{"debug":false}}`), 0o600)
_ = os.WriteFile("conf.d/tmp.toml", []byte(``), 0o600)
_ = dir.WriteFile("conf.d/tmp.json", []byte(`{"app":{"debug":false}}`), 0o600)
_ = dir.WriteFile("conf.d/tmp.toml", []byte(``), 0o600)
}

type testStruct struct {
Expand Down

0 comments on commit c4b8827

Please sign in to comment.