chore(tests): use t.TempDir to create temporary test directory [EE-3700] (#7612)

* create temporary test directory with t.TempDir
This commit is contained in:
Chao Geng
2022-09-14 13:59:47 +08:00
committed by GitHub
parent 1a9d793f2f
commit a7d458f0bd
36 changed files with 120 additions and 226 deletions

View File

@@ -1,11 +1,9 @@
package git
import (
"os"
"path/filepath"
"testing"
"github.com/docker/docker/pkg/ioutils"
"github.com/stretchr/testify/assert"
)
@@ -16,12 +14,10 @@ func TestService_ClonePrivateRepository_GitHub(t *testing.T) {
username := getRequiredValue(t, "GITHUB_USERNAME")
service := NewService()
dst, err := ioutils.TempDir("", "clone")
assert.NoError(t, err)
defer os.RemoveAll(dst)
dst := t.TempDir()
repositoryUrl := "https://github.com/portainer/private-test-repository.git"
err = service.CloneRepository(dst, repositoryUrl, "refs/heads/main", username, accessToken)
err := service.CloneRepository(dst, repositoryUrl, "refs/heads/main", username, accessToken)
assert.NoError(t, err)
assert.FileExists(t, filepath.Join(dst, "README.md"))
}