libnetwork/resolvconf: fix TestGet() testing wrong path

The test was assuming that the "source" file was always "/etc/resolv.conf",
but the `Get()` function uses `Path()` to find the location of resolv.conf,
which may be different.

While at it, also changed some `t.Fatalf()` to `t.Errorf()`, and renamed
some variables for clarity.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2022-10-01 16:47:24 +02:00
parent 55d18b7db9
commit fc1e698914
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C

View file

@ -7,19 +7,19 @@ import (
)
func TestGet(t *testing.T) {
resolvConfUtils, err := Get()
actual, err := Get()
if err != nil {
t.Fatal(err)
}
resolvConfSystem, err := os.ReadFile("/etc/resolv.conf")
expected, err := os.ReadFile(Path())
if err != nil {
t.Fatal(err)
}
if string(resolvConfUtils.Content) != string(resolvConfSystem) {
t.Fatalf("/etc/resolv.conf and GetResolvConf have different content.")
if !bytes.Equal(actual.Content, expected) {
t.Errorf("%s and GetResolvConf have different content.", Path())
}
if !bytes.Equal(resolvConfUtils.Hash, hashData(resolvConfSystem)) {
t.Fatalf("/etc/resolv.conf and GetResolvConf have different hashes.")
if !bytes.Equal(actual.Hash, hashData(expected)) {
t.Errorf("%s and GetResolvConf have different hashes.", Path())
}
}