Skip to content

Commit

Permalink
add tests for AddRoutes to new profile
Browse files Browse the repository at this point in the history
  • Loading branch information
guumaster committed Apr 19, 2020
1 parent e85efc3 commit 60a8e1f
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions pkg/host/file/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,36 @@ func TestManagerRoutes(t *testing.T) {
assert.Contains(t, string(c), added)
})

t.Run("AddRoutes new", func(t *testing.T) {
mem := CreateBasicFS(t)

f, err := NewWithFs("/tmp/etc/hosts", mem)
assert.NoError(t, err)

h, _ := mem.OpenFile("/tmp/etc/hosts", os.O_CREATE|os.O_RDWR|os.O_TRUNC, 0644)

err = f.AddRoutes("awesome", "3.3.3.4", []string{"host1.loc", "host2.loc"})
assert.NoError(t, err)

err = f.Flush()
assert.NoError(t, err)
f.Close()

c, err := afero.ReadFile(mem, h.Name())
assert.NoError(t, err)

assert.Contains(t, string(c), DefaultProfile)
assert.Contains(t, string(c), Banner)
assert.Contains(t, string(c), TestEnabledProfile)
var added = `
# profile.on awesome
3.3.3.4 host1.loc
3.3.3.4 host2.loc
# end
`
assert.Contains(t, string(c), added)
})

t.Run("RemoveRoutes", func(t *testing.T) {
mem := CreateBasicFS(t)

Expand Down

0 comments on commit 60a8e1f

Please sign in to comment.