Browse Source

more test fixes for comments

tags/v3.1.0
Chris Wiegman 5 months ago
parent
commit
43ab4f7854
Signed by: chriswiegman <chris@chriswiegman.com> GPG Key ID: 2B23D7A74FDE2DF4
2 changed files with 6 additions and 13 deletions
  1. +3
    -12
      hostsFile_test.go
  2. +3
    -1
      utils.go

+ 3
- 12
hostsFile_test.go View File

@@ -48,7 +48,6 @@ func TestHostsAddWhenIpHasOtherHosts(t *testing.T) {
NewHostsLine("10.0.0.7 nada"),
NewHostsLine("10.0.0.7 yadda"),
NewHostsLine("10.0.0.7 brada"),
NewHostsLine("10.0.0.7 yadda"),
}

if !reflect.DeepEqual(hosts.Lines, expectedLines) {
@@ -61,7 +60,6 @@ func TestHostsAddWithComment(t *testing.T) {
hosts.Lines = []HostsLine{
NewHostsLine("127.0.0.1 yadda"),
NewHostsLine("10.0.0.7 nada"),
NewHostsLine("10.0.0.7 yadda"),
}

hosts.Add("10.0.0.7", "Test Comment", "brada", "yadda")
@@ -69,17 +67,10 @@ func TestHostsAddWithComment(t *testing.T) {
expectedLines := []HostsLine{
NewHostsLine("127.0.0.1 yadda"),
NewHostsLine("10.0.0.7 nada"),
NewHostsLine("10.0.0.7 yadda"),
NewHostsLine("10.0.0.7 brada #Test Comment"),
NewHostsLine("10.0.0.7 yadda #Test Comment"),
}

bradaLine := NewHostsLine("10.0.0.7 brada")
yaddaLine := NewHostsLine("10.0.0.7 yadda")
bradaLine.comment = "Test Comment"
yaddaLine.comment = "Test Comment"

expectedLines = append(expectedLines, bradaLine)
expectedLines = append(expectedLines, yaddaLine)

if !reflect.DeepEqual(hosts.Lines, expectedLines) {
t.Error("Add entry failed to append entry.")
}
@@ -154,7 +145,7 @@ func TestHostsRemoveLineWithComments(t *testing.T) {
}

nadaLine := NewHostsLine("10.0.0.7 nada")
nadaLine.comment = "Test comment"
nadaLine.Comment = "Test comment"

hosts.Lines = append(hosts.Lines, nadaLine)



+ 3
- 1
utils.go View File

@@ -18,10 +18,12 @@ func itemInSlice(item string, list []string) bool {
func buildRawLine(ip string, host, comment string) string {
output := ip

output = fmt.Sprintf("%s %s", output, host)

if len(comment) > 0 {
comment = "#" + comment
output = fmt.Sprintf("%s %s", output, comment)
}
output = fmt.Sprintf("%s %s %s", output, host, comment)

return output
}


Loading…
Cancel
Save