go 1.13 compatibility

pull/4965/head
Dmitry Salakhov 4 years ago
parent a3ec2f8e85
commit 6d8f5e7479

@ -9,6 +9,7 @@ import (
"path/filepath"
"testing"
"github.com/docker/docker/pkg/ioutils"
"github.com/stretchr/testify/assert"
)
@ -26,7 +27,7 @@ func listFiles(dir string) []string {
}
func Test_shouldCreateArhive(t *testing.T) {
tmpdir, _ := os.MkdirTemp("", "backup")
tmpdir, _ := ioutils.TempDir("", "backup")
defer os.RemoveAll(tmpdir)
content := []byte("content")
@ -39,7 +40,7 @@ func Test_shouldCreateArhive(t *testing.T) {
assert.Nil(t, err)
assert.Equal(t, filepath.Join(tmpdir, fmt.Sprintf("%s.tar.gz", filepath.Base(tmpdir))), gzPath)
extractionDir, _ := os.MkdirTemp("", "extract")
extractionDir, _ := ioutils.TempDir("", "extract")
defer os.RemoveAll(extractionDir)
cmd := exec.Command("tar", "-xzf", gzPath, "-C", extractionDir)
@ -62,7 +63,7 @@ func Test_shouldCreateArhive(t *testing.T) {
}
func Test_shouldCreateArhiveXXXXX(t *testing.T) {
tmpdir, _ := os.MkdirTemp("", "backup")
tmpdir, _ := ioutils.TempDir("", "backup")
defer os.RemoveAll(tmpdir)
content := []byte("content")
@ -75,7 +76,7 @@ func Test_shouldCreateArhiveXXXXX(t *testing.T) {
assert.Nil(t, err)
assert.Equal(t, filepath.Join(tmpdir, fmt.Sprintf("%s.tar.gz", filepath.Base(tmpdir))), gzPath)
extractionDir, _ := os.MkdirTemp("", "extract")
extractionDir, _ := ioutils.TempDir("", "extract")
defer os.RemoveAll(extractionDir)
r, _ := os.Open(gzPath)

@ -2,7 +2,6 @@ package backup
import (
"fmt"
"io/fs"
"os"
"path/filepath"
"time"
@ -14,7 +13,7 @@ import (
"github.com/portainer/portainer/api/http/offlinegate"
)
const rwxr__r__ fs.FileMode = 0744
const rwxr__r__ os.FileMode = 0744
var filesToBackup = []string{"compose", "config.json", "custom_templates", "edge_jobs", "edge_stacks", "extensions", "portainer.key", "portainer.pub", "tls"}

@ -7,6 +7,7 @@ import (
"path/filepath"
"testing"
"github.com/docker/docker/pkg/ioutils"
"github.com/stretchr/testify/assert"
)
@ -30,7 +31,7 @@ func contains(t *testing.T, list []string, path string) {
}
func Test_copyFile_returnsError_whenSourceDoesNotExist(t *testing.T) {
tmpdir, _ := os.MkdirTemp("", "backup")
tmpdir, _ := ioutils.TempDir("", "backup")
defer os.RemoveAll(tmpdir)
err := copyFile("does-not-exist", tmpdir)
@ -38,7 +39,7 @@ func Test_copyFile_returnsError_whenSourceDoesNotExist(t *testing.T) {
}
func Test_copyFile_shouldMakeAbackup(t *testing.T) {
tmpdir, _ := os.MkdirTemp("", "backup")
tmpdir, _ := ioutils.TempDir("", "backup")
defer os.RemoveAll(tmpdir)
content := []byte("content")
@ -52,7 +53,7 @@ func Test_copyFile_shouldMakeAbackup(t *testing.T) {
}
func Test_copyDir_shouldCopyAllFilesAndDirectories(t *testing.T) {
destination, _ := os.MkdirTemp("", "destination")
destination, _ := ioutils.TempDir("", "destination")
defer os.RemoveAll(destination)
err := copyDir("./test_assets/copy_test", destination)
assert.Nil(t, err)
@ -65,7 +66,7 @@ func Test_copyDir_shouldCopyAllFilesAndDirectories(t *testing.T) {
}
func Test_backupPath_shouldSkipWhenNotExist(t *testing.T) {
tmpdir, _ := os.MkdirTemp("", "backup")
tmpdir, _ := ioutils.TempDir("", "backup")
defer os.RemoveAll(tmpdir)
err := copyPath("does-not-exists", tmpdir)
@ -75,7 +76,7 @@ func Test_backupPath_shouldSkipWhenNotExist(t *testing.T) {
}
func Test_backupPath_shouldCopyFile(t *testing.T) {
tmpdir, _ := os.MkdirTemp("", "backup")
tmpdir, _ := ioutils.TempDir("", "backup")
defer os.RemoveAll(tmpdir)
content := []byte("content")
@ -91,7 +92,7 @@ func Test_backupPath_shouldCopyFile(t *testing.T) {
}
func Test_backupPath_shouldCopyDir(t *testing.T) {
destination, _ := os.MkdirTemp("", "destination")
destination, _ := ioutils.TempDir("", "destination")
defer os.RemoveAll(destination)
err := copyPath("./test_assets/copy_test", destination)
assert.Nil(t, err)

@ -7,11 +7,12 @@ import (
"path/filepath"
"testing"
"github.com/docker/docker/pkg/ioutils"
"github.com/stretchr/testify/assert"
)
func Test_encryptAndDecrypt_withTheSamePassword(t *testing.T) {
tmpdir, _ := os.MkdirTemp("", "encrypt")
tmpdir, _ := ioutils.TempDir("", "encrypt")
defer os.RemoveAll(tmpdir)
var (
@ -51,7 +52,7 @@ func Test_encryptAndDecrypt_withTheSamePassword(t *testing.T) {
}
func Test_encryptAndDecrypt_withEmptyPassword(t *testing.T) {
tmpdir, _ := os.MkdirTemp("", "encrypt")
tmpdir, _ := ioutils.TempDir("", "encrypt")
defer os.RemoveAll(tmpdir)
var (
@ -91,7 +92,7 @@ func Test_encryptAndDecrypt_withEmptyPassword(t *testing.T) {
}
func Test_decryptWithDifferentPassphrase_shouldProduceWrongResult(t *testing.T) {
tmpdir, _ := os.MkdirTemp("", "encrypt")
tmpdir, _ := ioutils.TempDir("", "encrypt")
defer os.RemoveAll(tmpdir)
var (

@ -15,6 +15,7 @@ import (
"testing"
"time"
"github.com/docker/docker/pkg/ioutils"
"github.com/portainer/portainer/api/adminmonitor"
"github.com/portainer/portainer/api/crypto"
"github.com/portainer/portainer/api/http/offlinegate"
@ -54,7 +55,7 @@ func Test_backupHandlerWithoutPassword_shouldCreateATarballArchive(t *testing.T)
response := w.Result()
body, _ := io.ReadAll(response.Body)
tmpdir, _ := os.MkdirTemp("", "backup")
tmpdir, _ := ioutils.TempDir("", "backup")
defer os.RemoveAll(tmpdir)
archivePath := filepath.Join(tmpdir, "archive.tar.gz")
@ -91,7 +92,7 @@ func Test_backupHandlerWithPassword_shouldCreateEncryptedATarballArchive(t *test
response := w.Result()
body, _ := io.ReadAll(response.Body)
tmpdir, _ := os.MkdirTemp("", "backup")
tmpdir, _ := ioutils.TempDir("", "backup")
defer os.RemoveAll(tmpdir)
dr, err := crypto.AesDecrypt(bytes.NewReader(body), []byte("secret"))

Loading…
Cancel
Save