mirror of
https://github.com/containers/podman.git
synced 2025-08-06 19:44:14 +08:00
libpod/runtime_img_test.go Unit Tests
Unit tests for getRegistry related functions. Signed-off-by: baude <bbaude@redhat.com>
This commit is contained in:
@ -1,12 +1,11 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"testing"
|
||||||
|
|
||||||
"github.com/stretchr/testify/assert"
|
|
||||||
spec "github.com/opencontainers/runtime-spec/specs-go"
|
spec "github.com/opencontainers/runtime-spec/specs-go"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCreateConfig_GetVolumeMounts(t *testing.T) {
|
func TestCreateConfig_GetVolumeMounts(t *testing.T) {
|
||||||
|
54
libpod/runtime_img_test.go
Normal file
54
libpod/runtime_img_test.go
Normal file
@ -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"}))
|
||||||
|
}
|
@ -1,10 +1,10 @@
|
|||||||
package libpod
|
package libpod
|
||||||
|
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
sliceData = []string{"one", "two", "three", "four"}
|
sliceData = []string{"one", "two", "three", "four"}
|
||||||
)
|
)
|
||||||
|
Reference in New Issue
Block a user