executor/oci: add TestResolvConfNotExist
Signed-off-by: Tibor Vass <tibor@docker.com>v0.7
parent
f7042823e3
commit
0696bf3885
|
@ -16,6 +16,9 @@ var g flightcontrol.Group
|
|||
var notFirstRun bool
|
||||
var lastNotEmpty bool
|
||||
|
||||
// overridden by tests
|
||||
var resolvconfGet = resolvconf.Get
|
||||
|
||||
type DNSConfig struct {
|
||||
Nameservers []string
|
||||
Options []string
|
||||
|
@ -59,7 +62,7 @@ func GetResolvConf(ctx context.Context, stateDir string, idmap *idtools.Identity
|
|||
}
|
||||
|
||||
var dt []byte
|
||||
f, err := resolvconf.Get()
|
||||
f, err := resolvconfGet()
|
||||
if err != nil {
|
||||
if !os.IsNotExist(err) {
|
||||
return "", err
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
package oci
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/docker/libnetwork/resolvconf"
|
||||
"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)
|
||||
}
|
Loading…
Reference in New Issue