-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor code to isolate packet structure from UDP connection logic
- Loading branch information
Showing
5 changed files
with
159 additions
and
122 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package main | ||
|
||
//////////////////////////////////////////////////////////////////////////////// | ||
|
||
import ( | ||
"net" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
//////////////////////////////////////////////////////////////////////////////// | ||
|
||
func TestIPFromInterface(t *testing.T) { | ||
interfaces, err := net.Interfaces() | ||
assert.Nil(t, err) | ||
|
||
// We can't actually enforce that we get a valid IP, but either the error | ||
// or the pointer should be nil. | ||
for _, i := range interfaces { | ||
addr, err := ipFromInterface(i.Name) | ||
if err == nil { | ||
assert.NotNil(t, addr) | ||
} else { | ||
assert.Nil(t, addr) | ||
} | ||
} | ||
} | ||
|
||
func TestIPFromInterfaceNegative(t *testing.T) { | ||
// Test some fake interfaces. | ||
var NegativeTestCases = []struct { | ||
iface string | ||
}{ | ||
{"fake-interface-0"}, | ||
{"fake-interface-1"}, | ||
} | ||
|
||
for _, tc := range NegativeTestCases { | ||
addr, err := ipFromInterface(tc.iface) | ||
assert.Nil(t, addr) | ||
assert.NotNil(t, err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters