mirror of
https://github.com/kemko/nomad.git
synced 2026-01-06 18:35:44 +03:00
chore: Fix docker test linting
Due to https://github.com/tsenart/deadcode/issues/3 we can't specify these consts on their own. This moves them into the _platform_test.go files to avoid creating a package that only exposes a couple of values.
This commit is contained in:
@@ -4,6 +4,9 @@ package docker
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -11,6 +14,7 @@ import (
|
||||
"time"
|
||||
|
||||
docker "github.com/fsouza/go-dockerclient"
|
||||
"github.com/hashicorp/nomad/client/allocdir"
|
||||
"github.com/hashicorp/nomad/client/testutil"
|
||||
"github.com/hashicorp/nomad/helper/uuid"
|
||||
"github.com/hashicorp/nomad/plugins/drivers"
|
||||
@@ -641,3 +645,51 @@ func TestDockerDriver_CreateContainerConfig_MountsCombined(t *testing.T) {
|
||||
})
|
||||
require.EqualValues(t, expectedDevices, foundDevices)
|
||||
}
|
||||
|
||||
func newTaskConfig(variant string, command []string) TaskConfig {
|
||||
// busyboxImageID is the ID stored in busybox.tar
|
||||
busyboxImageID := "busybox:1.29.3"
|
||||
|
||||
image := busyboxImageID
|
||||
loadImage := "busybox.tar"
|
||||
if variant != "" {
|
||||
image = fmt.Sprintf("%s-%s", busyboxImageID, variant)
|
||||
loadImage = fmt.Sprintf("busybox_%s.tar", variant)
|
||||
}
|
||||
|
||||
return TaskConfig{
|
||||
Image: image,
|
||||
LoadImage: loadImage,
|
||||
Command: command[0],
|
||||
Args: command[1:],
|
||||
}
|
||||
}
|
||||
|
||||
func copyImage(t *testing.T, taskDir *allocdir.TaskDir, image string) {
|
||||
dst := filepath.Join(taskDir.LocalDir, image)
|
||||
copyFile(filepath.Join("./test-resources/docker", image), dst, t)
|
||||
}
|
||||
|
||||
// copyFile moves an existing file to the destination
|
||||
func copyFile(src, dst string, t *testing.T) {
|
||||
in, err := os.Open(src)
|
||||
if err != nil {
|
||||
t.Fatalf("copying %v -> %v failed: %v", src, dst, err)
|
||||
}
|
||||
defer in.Close()
|
||||
out, err := os.Create(dst)
|
||||
if err != nil {
|
||||
t.Fatalf("copying %v -> %v failed: %v", src, dst, err)
|
||||
}
|
||||
defer func() {
|
||||
if err := out.Close(); err != nil {
|
||||
t.Fatalf("copying %v -> %v failed: %v", src, dst, err)
|
||||
}
|
||||
}()
|
||||
if _, err = io.Copy(out, in); err != nil {
|
||||
t.Fatalf("copying %v -> %v failed: %v", src, dst, err)
|
||||
}
|
||||
if err := out.Sync(); err != nil {
|
||||
t.Fatalf("copying %v -> %v failed: %v", src, dst, err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
package docker
|
||||
|
||||
import (
|
||||
testing "github.com/mitchellh/go-testing-interface"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/nomad/client/allocdir"
|
||||
)
|
||||
@@ -21,5 +21,5 @@ func newTaskConfig(variant string, command []string) TaskConfig {
|
||||
}
|
||||
}
|
||||
|
||||
func copyImage(t testing.T, taskDir *allocdir.TaskDir, image string) {
|
||||
func copyImage(t *testing.T, taskDir *allocdir.TaskDir, image string) {
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
// +build darwin dragonfly freebsd linux netbsd openbsd solaris
|
||||
|
||||
package docker
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/hashicorp/nomad/client/allocdir"
|
||||
testing "github.com/mitchellh/go-testing-interface"
|
||||
)
|
||||
|
||||
func newTaskConfig(variant string, command []string) TaskConfig {
|
||||
// busyboxImageID is the ID stored in busybox.tar
|
||||
busyboxImageID := "busybox:1.29.3"
|
||||
|
||||
image := busyboxImageID
|
||||
loadImage := "busybox.tar"
|
||||
if variant != "" {
|
||||
image = fmt.Sprintf("%s-%s", busyboxImageID, variant)
|
||||
loadImage = fmt.Sprintf("busybox_%s.tar", variant)
|
||||
}
|
||||
|
||||
return TaskConfig{
|
||||
Image: image,
|
||||
LoadImage: loadImage,
|
||||
Command: command[0],
|
||||
Args: command[1:],
|
||||
}
|
||||
}
|
||||
|
||||
func copyImage(t testing.T, taskDir *allocdir.TaskDir, image string) {
|
||||
dst := filepath.Join(taskDir.LocalDir, image)
|
||||
copyFile(filepath.Join("./test-resources/docker", image), dst, t)
|
||||
}
|
||||
|
||||
// copyFile moves an existing file to the destination
|
||||
func copyFile(src, dst string, t testing.T) {
|
||||
in, err := os.Open(src)
|
||||
if err != nil {
|
||||
t.Fatalf("copying %v -> %v failed: %v", src, dst, err)
|
||||
}
|
||||
defer in.Close()
|
||||
out, err := os.Create(dst)
|
||||
if err != nil {
|
||||
t.Fatalf("copying %v -> %v failed: %v", src, dst, err)
|
||||
}
|
||||
defer func() {
|
||||
if err := out.Close(); err != nil {
|
||||
t.Fatalf("copying %v -> %v failed: %v", src, dst, err)
|
||||
}
|
||||
}()
|
||||
if _, err = io.Copy(out, in); err != nil {
|
||||
t.Fatalf("copying %v -> %v failed: %v", src, dst, err)
|
||||
}
|
||||
if err := out.Sync(); err != nil {
|
||||
t.Fatalf("copying %v -> %v failed: %v", src, dst, err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user