2019-10-10 23:15:25 +00:00
|
|
|
package oci
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"testing"
|
|
|
|
|
2021-06-05 15:54:05 +00:00
|
|
|
"github.com/docker/docker/libnetwork/resolvconf"
|
2019-10-10 23:15:25 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
// TestResolvConfNotExist modifies a global variable
|
|
|
|
// It must not run in parallel.
|
|
|
|
func TestResolvConfNotExist(t *testing.T) {
|
|
|
|
oldResolvconfGet := resolvconfGet
|
|
|
|
defer func() {
|
|
|
|
resolvconfGet = oldResolvconfGet
|
|
|
|
}()
|
|
|
|
resolvconfGet = func() (*resolvconf.File, error) {
|
|
|
|
return nil, os.ErrNotExist
|
|
|
|
}
|
|
|
|
|
|
|
|
defaultResolvConf := `
|
|
|
|
nameserver 8.8.8.8
|
|
|
|
nameserver 8.8.4.4
|
|
|
|
nameserver 2001:4860:4860::8888
|
|
|
|
nameserver 2001:4860:4860::8844`
|
|
|
|
|
|
|
|
dir, err := ioutil.TempDir("", "buildkit-test")
|
|
|
|
require.NoError(t, err)
|
|
|
|
defer os.RemoveAll(dir)
|
|
|
|
ctx := context.Background()
|
|
|
|
p, err := GetResolvConf(ctx, dir, nil, nil)
|
|
|
|
require.NoError(t, err)
|
|
|
|
b, err := ioutil.ReadFile(p)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.Equal(t, string(b), defaultResolvConf)
|
|
|
|
}
|