#!/bin/bash
. $(cd ${0%/*};pwd;)/../common.sh

comment="use default dns config"
md5=$(echo '# Generated by RunQ
options timeout:2
search example.com
nameserver 8.8.8.8
nameserver 8.8.4.4' | md5sum | awk '{print $1}')

docker run \
    --runtime runq \
    --name $(rand_name) \
    --rm \
    $image  \
    sh -c "echo '$md5  /etc/resolv.conf' > /x; md5sum -s -c /x"

checkrc $? 0 "$comment"

#
#
#
comment="force no dns config"
docker run \
    --runtime runq \
    --name $(rand_name) \
    --rm \
    -e RUNQ_DNS="" \
    -e RUNQ_DNS_OPTS="" \
    -e RUNQ_DNS_SEARCH="" \
    $image  \
    sh -c 'exit $(grep -c -v ^# /etc/resolv.conf);'

checkrc $? 0 "$comment"

#
#
#
comment="set custom dns config"
md5=$(echo '# Generated by RunQ
options timeout:7
search foo.com
nameserver 1.2.3.4
nameserver 5.5.5.5' | md5sum | awk '{print $1}')

docker run \
    --runtime runq \
    --name $(rand_name) \
    --rm \
    -e RUNQ_DNS="1.2.3.4,5.5.5.5" \
    -e RUNQ_DNS_OPTS="timeout:7" \
    -e RUNQ_DNS_SEARCH="foo.com" \
    $image  \
    sh -c "echo '$md5  /etc/resolv.conf' > /x; md5sum -s -c /x"

checkrc $? 0 "$comment"

#
#
#
comment="preserve resolv.conf"
md5=$(docker run --runtime=runc --network=none --rm \
	$image cat /etc/resolv.conf | md5sum | awk '{print $1}')
docker run \
    --runtime runq \
    --name $(rand_name) \
    --rm \
    -e RUNQ_DNS_PRESERVE="1" \
    $image  \
    sh -c "echo '$md5  /etc/resolv.conf' > /x; md5sum -s -c /x"

checkrc $? 0 "$comment"

myexit
