Skip to content

Commit 4b68b0f

Browse files
Merge pull request #25209 from Luap99/e2e-conf
test/e2e: improve write/removeConf()
2 parents cd33345 + dcdf82e commit 4b68b0f

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

test/e2e/common_test.go

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"github.com/containers/podman/v5/pkg/inspect"
2929
. "github.com/containers/podman/v5/test/utils"
3030
"github.com/containers/podman/v5/utils"
31+
"github.com/containers/storage/pkg/ioutils"
3132
"github.com/containers/storage/pkg/lockfile"
3233
"github.com/containers/storage/pkg/reexec"
3334
"github.com/containers/storage/pkg/stringid"
@@ -1187,19 +1188,21 @@ func (p *PodmanTestIntegration) makeOptions(args []string, options PodmanExecOpt
11871188
}
11881189

11891190
func writeConf(conf []byte, confPath string) {
1190-
if _, err := os.Stat(filepath.Dir(confPath)); os.IsNotExist(err) {
1191-
if err := os.MkdirAll(filepath.Dir(confPath), 0o777); err != nil {
1192-
GinkgoWriter.Println(err)
1193-
}
1194-
}
1195-
if err := os.WriteFile(confPath, conf, 0o777); err != nil {
1196-
GinkgoWriter.Println(err)
1197-
}
1191+
GinkgoHelper()
1192+
err := os.MkdirAll(filepath.Dir(confPath), 0o755)
1193+
Expect(err).ToNot(HaveOccurred())
1194+
1195+
err = ioutils.AtomicWriteFile(confPath, conf, 0o644)
1196+
Expect(err).ToNot(HaveOccurred())
11981197
}
11991198

12001199
func removeConf(confPath string) {
1201-
if err := os.Remove(confPath); err != nil {
1202-
GinkgoWriter.Println(err)
1200+
GinkgoHelper()
1201+
err := os.Remove(confPath)
1202+
// Network remove test will remove the config and then this can fail.
1203+
// If the config does not exists no reason to hard error here.
1204+
if !errors.Is(err, os.ErrNotExist) {
1205+
Expect(err).ToNot(HaveOccurred())
12031206
}
12041207
}
12051208

0 commit comments

Comments
 (0)