summaryrefslogtreecommitdiffhomepage
path: root/netboot/netconf_integ_test.go
diff options
context:
space:
mode:
authorAndrea Barberio <insomniac@slackware.it>2021-03-14 22:36:51 +0000
committerinsomniac <insomniacslk@users.noreply.github.com>2021-03-15 11:02:27 +0000
commitc51060810aaab9c8a0bd1b0fcbf72bc0b91e6427 (patch)
treee4f267e63b5eb584ef34851f871abcb8e6a9af80 /netboot/netconf_integ_test.go
parent28f74147e2e808a9465553b4d92eea14371e7ce8 (diff)
Switch to GitHub Actions
TravisCI not supported anymore. Signed-off-by: Andrea Barberio <insomniac@slackware.it>
Diffstat (limited to 'netboot/netconf_integ_test.go')
-rw-r--r--netboot/netconf_integ_test.go67
1 files changed, 47 insertions, 20 deletions
diff --git a/netboot/netconf_integ_test.go b/netboot/netconf_integ_test.go
index 30a7232..099296c 100644
--- a/netboot/netconf_integ_test.go
+++ b/netboot/netconf_integ_test.go
@@ -3,6 +3,9 @@
package netboot
import (
+ "fmt"
+ "io/ioutil"
+ "log"
"net"
"testing"
"time"
@@ -11,10 +14,9 @@ import (
"github.com/stretchr/testify/require"
)
-// Travis-CI uses ens4, and this test assumes that such interface
-// exists and is configurable. If you are running this test locally,
-// you may need to adjust this value.
-var ifname = "ens4"
+// The test assumes that the interface exists and is configurable.
+// If you are running this test locally, you may need to adjust this value.
+var ifname = "eth0"
func TestIfUp(t *testing.T) {
iface, err := IfUp(ifname, 2*time.Second)
@@ -28,24 +30,49 @@ func TestIfUpTimeout(t *testing.T) {
}
func TestConfigureInterface(t *testing.T) {
- nc := NetConf{
- Addresses: []AddrConf{
- AddrConf{IPNet: net.IPNet{IP: net.ParseIP("10.20.30.40")}},
+ // Linux-only. `netboot.ConfigureInterface` writes to /etc/resolv.conf when
+ // `NetConf.DNSServers` is set. In this test we make a backup of resolv.conf
+ // and subsequently restore it. This is really ugly, and not safe if
+ // multiple tests do the same.
+ resolvconf, err := ioutil.ReadFile("/etc/resolv.conf")
+ if err != nil {
+ panic(fmt.Sprintf("Failed to read /etc/resolv.conf: %v", err))
+ }
+ type testCase struct {
+ Name string
+ NetConf *NetConf
+ }
+ testCases := []testCase{
+ {
+ Name: "just IP addr",
+ NetConf: &NetConf{
+ Addresses: []AddrConf{
+ AddrConf{IPNet: net.IPNet{IP: net.ParseIP("10.20.30.40")}},
+ },
+ },
+ },
+ {
+ Name: "IP addr, DNS, and routers",
+ NetConf: &NetConf{
+ Addresses: []AddrConf{
+ AddrConf{IPNet: net.IPNet{IP: net.ParseIP("10.20.30.40")}},
+ },
+ DNSServers: []net.IP{net.ParseIP("8.8.8.8")},
+ DNSSearchList: []string{"slackware.it"},
+ Routers: []net.IP{net.ParseIP("10.20.30.254")},
+ },
},
}
- err := ConfigureInterface(ifname, &nc)
- require.NoError(t, err)
-}
+ for _, tc := range testCases {
+ t.Run(tc.Name, func(t *testing.T) {
+ require.NoError(t, ConfigureInterface(ifname, tc.NetConf))
-func TestConfigureInterfaceWithRouteAndDNS(t *testing.T) {
- nc := NetConf{
- Addresses: []AddrConf{
- AddrConf{IPNet: net.IPNet{IP: net.ParseIP("10.20.30.40")}},
- },
- DNSServers: []net.IP{net.ParseIP("8.8.8.8")},
- DNSSearchList: []string{"slackware.it"},
- Routers: []net.IP{net.ParseIP("10.20.30.254")},
+ // after the test, restore the content of /etc/resolv.conf . The permissions
+ // are used only if it didn't exist.
+ if err = ioutil.WriteFile("/etc/resolv.conf", resolvconf, 0644); err != nil {
+ panic(fmt.Sprintf("Failed to restore /etc/resolv.conf: %v", err))
+ }
+ log.Printf("Restored /etc/resolv.conf")
+ })
}
- err := ConfigureInterface(ifname, &nc)
- require.NoError(t, err)
}