tstun: add test to send a packet after Close()
This test serves two purposes: + check that Write() returns an error if the tstun has been closed. + ensure that the close-related code in tstun is exercised in a test case. We were getting spurious code coverage adds/drops based on timing of when the test case finished. Signed-off-by: Denton Gentry <dgentry@tailscale.com>
This commit is contained in:
parent
7c1a9e8616
commit
8578b0445d
|
@ -341,6 +341,22 @@ func TestAllocs(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestClose(t *testing.T) {
|
||||
ftun, tun := newFakeTUN(t.Logf, false)
|
||||
|
||||
data := udp4("1.2.3.4", "5.6.7.8", 98, 98)
|
||||
_, err := ftun.Write(data, 0)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
tun.Close()
|
||||
_, err = ftun.Write(data, 0)
|
||||
if err == nil {
|
||||
t.Error("Expected error from ftun.Write() after Close()")
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkWrite(b *testing.B) {
|
||||
ftun, tun := newFakeTUN(b.Logf, true)
|
||||
defer tun.Close()
|
||||
|
|
Loading…
Reference in New Issue