aboutsummaryrefslogtreecommitdiff
path: root/libpod/runtime_img_test.go
blob: a8cc2c941122ed42cfde55a5fcb0dcb9b2e366d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package libpod

import (
	"io/ioutil"
	"os"
	"reflect"
	"testing"

	sysreg "github.com/containers/libpod/v2/pkg/registries"
	"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 := sysreg.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 := sysreg.GetInsecureRegistries()
	assert.NoError(t, err)
	assert.True(t, reflect.DeepEqual(registries, []string{"two"}))
}