Skip to content

Commit

Permalink
tests: Add removal test when there is no crc section
Browse files Browse the repository at this point in the history
While the removal code when there is no crc section does not seem to
be impacted by the issues recently fixed, it does not hurt to have a
test for it.
  • Loading branch information
cfergeau authored and evidolob committed Dec 20, 2023
1 parent 711fab1 commit 42442e8
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions pkg/hosts/hosts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,22 @@ func TestRemoveMultipleLines(t *testing.T) {
assert.Equal(t, hostsTemplate+eol()+crcSection(), string(content))
}

func TestRemoveMultipleNoCrcSection(t *testing.T) {
dir, err := os.MkdirTemp("", "hosts")
assert.NoError(t, err)
defer os.RemoveAll(dir)

hostsFile := filepath.Join(dir, "hosts")
assert.NoError(t, os.WriteFile(hostsFile, []byte("192.168.130.11 entry1 entry2"+eol()+"192.168.130.11 entry3 entry4"), 0600))
host := hosts(t, hostsFile)

assert.NoError(t, host.Remove([]string{"entry1", "entry2", "entry3", "entry4"}))

content, err := os.ReadFile(hostsFile)
assert.NoError(t, err)
assert.Equal(t, "", string(content))
}

func hosts(t *testing.T, hostsFile string) Hosts {
config, _ := libhosty.NewHostsFileConfig(hostsFile)
file, err := libhosty.InitWithConfig(config)
Expand Down

0 comments on commit 42442e8

Please sign in to comment.