You've already forked sap-jenkins-library
mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-07-15 01:34:38 +02:00
test: use T.TempDir
to create temporary test directory (#3721)
This commit replaces `ioutil.TempDir` with `t.TempDir` in tests. The directory created by `t.TempDir` is automatically removed when the test and all its subtests complete. Prior to this commit, temporary directory created using `ioutil.TempDir` needs to be removed manually by calling `os.RemoveAll`, which is omitted in some tests. The error handling boilerplate e.g. defer func() { if err := os.RemoveAll(dir); err != nil { t.Fatal(err) } } is also tedious, but `t.TempDir` handles this for us nicely. Reference: https://pkg.go.dev/testing#T.TempDir Signed-off-by: Eng Zer Jun <engzerjun@gmail.com> Co-authored-by: Oliver Nocon <33484802+OliverNocon@users.noreply.github.com>
This commit is contained in:
@ -613,11 +613,9 @@ func TestReportGolangTestCoverage(t *testing.T) {
|
||||
|
||||
func TestPrepareLdflags(t *testing.T) {
|
||||
t.Parallel()
|
||||
dir, err := ioutil.TempDir("", "")
|
||||
defer os.RemoveAll(dir) // clean up
|
||||
assert.NoError(t, err, "Error when creating temp dir")
|
||||
dir := t.TempDir()
|
||||
|
||||
err = os.Mkdir(filepath.Join(dir, "commonPipelineEnvironment"), 0777)
|
||||
err := os.Mkdir(filepath.Join(dir, "commonPipelineEnvironment"), 0777)
|
||||
assert.NoError(t, err, "Error when creating folder structure")
|
||||
|
||||
err = ioutil.WriteFile(filepath.Join(dir, "commonPipelineEnvironment", "artifactVersion"), []byte("1.2.3"), 0666)
|
||||
|
Reference in New Issue
Block a user