mirror of
https://github.com/portainer/portainer.git
synced 2025-07-24 15:59:41 +02:00
go 1.13 compatibility
This commit is contained in:
parent
a3ec2f8e85
commit
6d8f5e7479
5 changed files with 20 additions and 17 deletions
|
@ -9,6 +9,7 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/docker/docker/pkg/ioutils"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -26,7 +27,7 @@ func listFiles(dir string) []string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_shouldCreateArhive(t *testing.T) {
|
func Test_shouldCreateArhive(t *testing.T) {
|
||||||
tmpdir, _ := os.MkdirTemp("", "backup")
|
tmpdir, _ := ioutils.TempDir("", "backup")
|
||||||
defer os.RemoveAll(tmpdir)
|
defer os.RemoveAll(tmpdir)
|
||||||
|
|
||||||
content := []byte("content")
|
content := []byte("content")
|
||||||
|
@ -39,7 +40,7 @@ func Test_shouldCreateArhive(t *testing.T) {
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.Equal(t, filepath.Join(tmpdir, fmt.Sprintf("%s.tar.gz", filepath.Base(tmpdir))), gzPath)
|
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)
|
defer os.RemoveAll(extractionDir)
|
||||||
|
|
||||||
cmd := exec.Command("tar", "-xzf", gzPath, "-C", 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) {
|
func Test_shouldCreateArhiveXXXXX(t *testing.T) {
|
||||||
tmpdir, _ := os.MkdirTemp("", "backup")
|
tmpdir, _ := ioutils.TempDir("", "backup")
|
||||||
defer os.RemoveAll(tmpdir)
|
defer os.RemoveAll(tmpdir)
|
||||||
|
|
||||||
content := []byte("content")
|
content := []byte("content")
|
||||||
|
@ -75,7 +76,7 @@ func Test_shouldCreateArhiveXXXXX(t *testing.T) {
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
assert.Equal(t, filepath.Join(tmpdir, fmt.Sprintf("%s.tar.gz", filepath.Base(tmpdir))), gzPath)
|
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)
|
defer os.RemoveAll(extractionDir)
|
||||||
|
|
||||||
r, _ := os.Open(gzPath)
|
r, _ := os.Open(gzPath)
|
||||||
|
|
|
@ -2,7 +2,6 @@ package backup
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/fs"
|
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"time"
|
"time"
|
||||||
|
@ -14,7 +13,7 @@ import (
|
||||||
"github.com/portainer/portainer/api/http/offlinegate"
|
"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"}
|
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"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/docker/docker/pkg/ioutils"
|
||||||
"github.com/stretchr/testify/assert"
|
"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) {
|
func Test_copyFile_returnsError_whenSourceDoesNotExist(t *testing.T) {
|
||||||
tmpdir, _ := os.MkdirTemp("", "backup")
|
tmpdir, _ := ioutils.TempDir("", "backup")
|
||||||
defer os.RemoveAll(tmpdir)
|
defer os.RemoveAll(tmpdir)
|
||||||
|
|
||||||
err := copyFile("does-not-exist", 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) {
|
func Test_copyFile_shouldMakeAbackup(t *testing.T) {
|
||||||
tmpdir, _ := os.MkdirTemp("", "backup")
|
tmpdir, _ := ioutils.TempDir("", "backup")
|
||||||
defer os.RemoveAll(tmpdir)
|
defer os.RemoveAll(tmpdir)
|
||||||
|
|
||||||
content := []byte("content")
|
content := []byte("content")
|
||||||
|
@ -52,7 +53,7 @@ func Test_copyFile_shouldMakeAbackup(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_copyDir_shouldCopyAllFilesAndDirectories(t *testing.T) {
|
func Test_copyDir_shouldCopyAllFilesAndDirectories(t *testing.T) {
|
||||||
destination, _ := os.MkdirTemp("", "destination")
|
destination, _ := ioutils.TempDir("", "destination")
|
||||||
defer os.RemoveAll(destination)
|
defer os.RemoveAll(destination)
|
||||||
err := copyDir("./test_assets/copy_test", destination)
|
err := copyDir("./test_assets/copy_test", destination)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
|
@ -65,7 +66,7 @@ func Test_copyDir_shouldCopyAllFilesAndDirectories(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_backupPath_shouldSkipWhenNotExist(t *testing.T) {
|
func Test_backupPath_shouldSkipWhenNotExist(t *testing.T) {
|
||||||
tmpdir, _ := os.MkdirTemp("", "backup")
|
tmpdir, _ := ioutils.TempDir("", "backup")
|
||||||
defer os.RemoveAll(tmpdir)
|
defer os.RemoveAll(tmpdir)
|
||||||
|
|
||||||
err := copyPath("does-not-exists", 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) {
|
func Test_backupPath_shouldCopyFile(t *testing.T) {
|
||||||
tmpdir, _ := os.MkdirTemp("", "backup")
|
tmpdir, _ := ioutils.TempDir("", "backup")
|
||||||
defer os.RemoveAll(tmpdir)
|
defer os.RemoveAll(tmpdir)
|
||||||
|
|
||||||
content := []byte("content")
|
content := []byte("content")
|
||||||
|
@ -91,7 +92,7 @@ func Test_backupPath_shouldCopyFile(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_backupPath_shouldCopyDir(t *testing.T) {
|
func Test_backupPath_shouldCopyDir(t *testing.T) {
|
||||||
destination, _ := os.MkdirTemp("", "destination")
|
destination, _ := ioutils.TempDir("", "destination")
|
||||||
defer os.RemoveAll(destination)
|
defer os.RemoveAll(destination)
|
||||||
err := copyPath("./test_assets/copy_test", destination)
|
err := copyPath("./test_assets/copy_test", destination)
|
||||||
assert.Nil(t, err)
|
assert.Nil(t, err)
|
||||||
|
|
|
@ -7,11 +7,12 @@ import (
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/docker/docker/pkg/ioutils"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Test_encryptAndDecrypt_withTheSamePassword(t *testing.T) {
|
func Test_encryptAndDecrypt_withTheSamePassword(t *testing.T) {
|
||||||
tmpdir, _ := os.MkdirTemp("", "encrypt")
|
tmpdir, _ := ioutils.TempDir("", "encrypt")
|
||||||
defer os.RemoveAll(tmpdir)
|
defer os.RemoveAll(tmpdir)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -51,7 +52,7 @@ func Test_encryptAndDecrypt_withTheSamePassword(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_encryptAndDecrypt_withEmptyPassword(t *testing.T) {
|
func Test_encryptAndDecrypt_withEmptyPassword(t *testing.T) {
|
||||||
tmpdir, _ := os.MkdirTemp("", "encrypt")
|
tmpdir, _ := ioutils.TempDir("", "encrypt")
|
||||||
defer os.RemoveAll(tmpdir)
|
defer os.RemoveAll(tmpdir)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -91,7 +92,7 @@ func Test_encryptAndDecrypt_withEmptyPassword(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test_decryptWithDifferentPassphrase_shouldProduceWrongResult(t *testing.T) {
|
func Test_decryptWithDifferentPassphrase_shouldProduceWrongResult(t *testing.T) {
|
||||||
tmpdir, _ := os.MkdirTemp("", "encrypt")
|
tmpdir, _ := ioutils.TempDir("", "encrypt")
|
||||||
defer os.RemoveAll(tmpdir)
|
defer os.RemoveAll(tmpdir)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|
|
@ -15,6 +15,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/docker/docker/pkg/ioutils"
|
||||||
"github.com/portainer/portainer/api/adminmonitor"
|
"github.com/portainer/portainer/api/adminmonitor"
|
||||||
"github.com/portainer/portainer/api/crypto"
|
"github.com/portainer/portainer/api/crypto"
|
||||||
"github.com/portainer/portainer/api/http/offlinegate"
|
"github.com/portainer/portainer/api/http/offlinegate"
|
||||||
|
@ -54,7 +55,7 @@ func Test_backupHandlerWithoutPassword_shouldCreateATarballArchive(t *testing.T)
|
||||||
response := w.Result()
|
response := w.Result()
|
||||||
body, _ := io.ReadAll(response.Body)
|
body, _ := io.ReadAll(response.Body)
|
||||||
|
|
||||||
tmpdir, _ := os.MkdirTemp("", "backup")
|
tmpdir, _ := ioutils.TempDir("", "backup")
|
||||||
defer os.RemoveAll(tmpdir)
|
defer os.RemoveAll(tmpdir)
|
||||||
|
|
||||||
archivePath := filepath.Join(tmpdir, "archive.tar.gz")
|
archivePath := filepath.Join(tmpdir, "archive.tar.gz")
|
||||||
|
@ -91,7 +92,7 @@ func Test_backupHandlerWithPassword_shouldCreateEncryptedATarballArchive(t *test
|
||||||
response := w.Result()
|
response := w.Result()
|
||||||
body, _ := io.ReadAll(response.Body)
|
body, _ := io.ReadAll(response.Body)
|
||||||
|
|
||||||
tmpdir, _ := os.MkdirTemp("", "backup")
|
tmpdir, _ := ioutils.TempDir("", "backup")
|
||||||
defer os.RemoveAll(tmpdir)
|
defer os.RemoveAll(tmpdir)
|
||||||
|
|
||||||
dr, err := crypto.AesDecrypt(bytes.NewReader(body), []byte("secret"))
|
dr, err := crypto.AesDecrypt(bytes.NewReader(body), []byte("secret"))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue