github.com/containers/libpod@v1.9.4-0.20220419124438-4284fd425507/libpod/runtime_img_test.go (about) 1 package libpod 2 3 import ( 4 "io/ioutil" 5 "os" 6 "reflect" 7 "testing" 8 9 sysreg "github.com/containers/libpod/pkg/registries" 10 "github.com/stretchr/testify/assert" 11 ) 12 13 var ( 14 registry = `[registries.search] 15 registries = ['one'] 16 17 [registries.insecure] 18 registries = ['two']` 19 ) 20 21 func createTmpFile(content []byte) (string, error) { 22 tmpfile, err := ioutil.TempFile(os.TempDir(), "unittest") 23 if err != nil { 24 return "", err 25 } 26 27 if _, err := tmpfile.Write(content); err != nil { 28 return "", err 29 30 } 31 if err := tmpfile.Close(); err != nil { 32 return "", err 33 } 34 return tmpfile.Name(), nil 35 } 36 37 func TestGetRegistries(t *testing.T) { 38 registryPath, err := createTmpFile([]byte(registry)) 39 assert.NoError(t, err) 40 defer os.Remove(registryPath) 41 os.Setenv("REGISTRIES_CONFIG_PATH", registryPath) 42 registries, err := sysreg.GetRegistries() 43 assert.NoError(t, err) 44 assert.True(t, reflect.DeepEqual(registries, []string{"one"})) 45 } 46 47 func TestGetInsecureRegistries(t *testing.T) { 48 registryPath, err := createTmpFile([]byte(registry)) 49 assert.NoError(t, err) 50 os.Setenv("REGISTRIES_CONFIG_PATH", registryPath) 51 defer os.Remove(registryPath) 52 registries, err := sysreg.GetInsecureRegistries() 53 assert.NoError(t, err) 54 assert.True(t, reflect.DeepEqual(registries, []string{"two"})) 55 }