Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
network: Add a testcase for setupDNS
Browse files Browse the repository at this point in the history
setupDNS adds DNS to the Kata guest VM.
Add a testcase for that function.

Fixes: #635

Signed-off-by: Nitesh Konkar <[email protected]>
  • Loading branch information
nitkon committed Sep 11, 2019
1 parent d733185 commit e01f23c
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@
package main

import (
"io/ioutil"
"net"
"os"
"reflect"
"runtime"
"strings"
"testing"

"github.com/kata-containers/agent/pkg/types"
Expand Down Expand Up @@ -422,3 +425,33 @@ func TestListRoutesWithTwoInterfacesSameSubnet(t *testing.T) {
"Route listed didn't match: got %+v, expecting %+v", results.Routes[2], expectedRoutes[2])

}

// As mounting errors out in permission denied, so test kataGuestSandboxDNSFile contents only.
func TestSetupDNS(t *testing.T) {
skipUnlessRoot(t)

tmpfile, err := ioutil.TempFile("", "resolv.conf")
assert.NoError(t, err)
guestDNSFile = tmpfile.Name()

tmpfile, err = ioutil.TempFile("", "resolv.conf")
assert.NoError(t, err)
kataGuestSandboxDNSFile = tmpfile.Name()

defer os.RemoveAll(guestDNSFile)
defer os.RemoveAll(kataGuestSandboxDNSFile)

dns := []string{
"nameserver 8.8.8.8",
"nameserver 8.8.4.4",
}

err = setupDNS(dns)
assert.NoError(t, err)

content, err := ioutil.ReadFile(guestDNSFile)
assert.NoError(t, err)

expectedDNS := strings.Split(string(content), "\n")
assert.Equal(t, dns, expectedDNS)
}

0 comments on commit e01f23c

Please sign in to comment.