52e64d2f09
This patch fixes the fact that the tests for pkg/networkfs/etchosts couldn't build due to syntax errors. Docker-DCO-1.1-Signed-off-by: Aleksa Sarai <cyphar@cyphar.com> (github: cyphar)
74 lines
1.5 KiB
Go
74 lines
1.5 KiB
Go
package etchosts
|
|
|
|
import (
|
|
"bytes"
|
|
"io/ioutil"
|
|
"os"
|
|
"testing"
|
|
)
|
|
|
|
func TestBuildHostnameDomainname(t *testing.T) {
|
|
file, err := ioutil.TempFile("", "")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer os.Remove(file.Name())
|
|
|
|
err = Build(file.Name(), "10.11.12.13", "testhostname", "testdomainname", nil)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
content, err := ioutil.ReadFile(file.Name())
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if expected := "10.11.12.13\ttesthostname.testdomainname testhostname\n"; !bytes.Contains(content, []byte(expected)) {
|
|
t.Fatalf("Expected to find '%s' got '%s'", expected, content)
|
|
}
|
|
}
|
|
|
|
func TestBuildHostname(t *testing.T) {
|
|
file, err := ioutil.TempFile("", "")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer os.Remove(file.Name())
|
|
|
|
err = Build(file.Name(), "10.11.12.13", "testhostname", "", nil)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
content, err := ioutil.ReadFile(file.Name())
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if expected := "10.11.12.13\ttesthostname\n"; !bytes.Contains(content, []byte(expected)) {
|
|
t.Fatalf("Expected to find '%s' got '%s'", expected, content)
|
|
}
|
|
}
|
|
|
|
func TestBuildNoIP(t *testing.T) {
|
|
file, err := ioutil.TempFile("", "")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
defer os.Remove(file.Name())
|
|
|
|
err = Build(file.Name(), "", "testhostname", "", nil)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
content, err := ioutil.ReadFile(file.Name())
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if expected := ""; !bytes.Contains(content, []byte(expected)) {
|
|
t.Fatalf("Expected to find '%s' got '%s'", expected, content)
|
|
}
|
|
}
|