summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmd/kpod/create_cli.go2
-rw-r--r--cmd/kpod/spec_test.go19
-rw-r--r--libpod/runtime_img_test.go54
-rw-r--r--libpod/util_test.go6
4 files changed, 67 insertions, 14 deletions
diff --git a/cmd/kpod/create_cli.go b/cmd/kpod/create_cli.go
index 1cc00adc5..eaad46591 100644
--- a/cmd/kpod/create_cli.go
+++ b/cmd/kpod/create_cli.go
@@ -36,7 +36,7 @@ func getAllEnvironmentVariables(envFiles, envInput []string) ([]string, error) {
env = append(env, defaultEnvVariables...)
}
// Each environment variable must be in the K=V format
- for _,i := range env{
+ for _, i := range env {
spliti := strings.Split(i, "=")
if len(spliti) != 2 {
return env, errors.Errorf("environment variables must be in the format KEY=VALUE: %s is invalid", i)
diff --git a/cmd/kpod/spec_test.go b/cmd/kpod/spec_test.go
index 2f023f201..c3de84324 100644
--- a/cmd/kpod/spec_test.go
+++ b/cmd/kpod/spec_test.go
@@ -1,20 +1,19 @@
package main
-
import (
- "testing"
"reflect"
+ "testing"
- "github.com/stretchr/testify/assert"
spec "github.com/opencontainers/runtime-spec/specs-go"
+ "github.com/stretchr/testify/assert"
)
func TestCreateConfig_GetVolumeMounts(t *testing.T) {
data := spec.Mount{
Destination: "/foobar",
- Type: "bind",
- Source: "foobar",
- Options: []string{"ro", "rbind"},
+ Type: "bind",
+ Source: "foobar",
+ Options: []string{"ro", "rbind"},
}
config := createConfig{
volumes: []string{"foobar:/foobar:ro"},
@@ -26,11 +25,11 @@ func TestCreateConfig_GetVolumeMounts(t *testing.T) {
func TestCreateConfig_GetTmpfsMounts(t *testing.T) {
data := spec.Mount{
Destination: "/homer",
- Type: "tmpfs",
- Source: "tmpfs",
- Options: []string{"rw", "size=787448k", "mode=1777"},
+ Type: "tmpfs",
+ Source: "tmpfs",
+ Options: []string{"rw", "size=787448k", "mode=1777"},
}
- config:= createConfig{
+ config := createConfig{
tmpfs: []string{"/homer:rw,size=787448k,mode=1777"},
}
tmpfsMount := config.GetTmpfsMounts()
diff --git a/libpod/runtime_img_test.go b/libpod/runtime_img_test.go
new file mode 100644
index 000000000..f7f7128a4
--- /dev/null
+++ b/libpod/runtime_img_test.go
@@ -0,0 +1,54 @@
+package libpod
+
+import (
+ "io/ioutil"
+ "os"
+ "reflect"
+ "testing"
+
+ "github.com/stretchr/testify/assert"
+)
+
+var (
+ registry = `[registries.search]
+registries = ['one']
+
+[registries.insecure]
+registries = ['two']`
+)
+
+func createTmpFile(content []byte) (string, error) {
+ tmpfile, err := ioutil.TempFile(os.TempDir(), "unittest")
+ if err != nil {
+ return "", err
+ }
+
+ if _, err := tmpfile.Write(content); err != nil {
+ return "", err
+
+ }
+ if err := tmpfile.Close(); err != nil {
+ return "", err
+ }
+ return tmpfile.Name(), nil
+}
+
+func TestGetRegistries(t *testing.T) {
+ registryPath, err := createTmpFile([]byte(registry))
+ assert.NoError(t, err)
+ defer os.Remove(registryPath)
+ os.Setenv("REGISTRIES_CONFIG_PATH", registryPath)
+ registries, err := GetRegistries()
+ assert.NoError(t, err)
+ assert.True(t, reflect.DeepEqual(registries, []string{"one"}))
+}
+
+func TestGetInsecureRegistries(t *testing.T) {
+ registryPath, err := createTmpFile([]byte(registry))
+ assert.NoError(t, err)
+ os.Setenv("REGISTRIES_CONFIG_PATH", registryPath)
+ defer os.Remove(registryPath)
+ registries, err := GetInsecureRegistries()
+ assert.NoError(t, err)
+ assert.True(t, reflect.DeepEqual(registries, []string{"two"}))
+}
diff --git a/libpod/util_test.go b/libpod/util_test.go
index b3d336d1f..24e5fdfac 100644
--- a/libpod/util_test.go
+++ b/libpod/util_test.go
@@ -1,10 +1,10 @@
package libpod
-
import (
- "testing"
"github.com/stretchr/testify/assert"
+ "testing"
)
+
var (
sliceData = []string{"one", "two", "three", "four"}
)
@@ -16,4 +16,4 @@ func TestStringInSlice(t *testing.T) {
assert.False(t, StringInSlice("five", sliceData))
// string is not in empty slice
assert.False(t, StringInSlice("one", []string{}))
-} \ No newline at end of file
+}