summaryrefslogtreecommitdiff
path: root/goprocnet_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'goprocnet_test.go')
-rw-r--r--goprocnet_test.go39
1 files changed, 39 insertions, 0 deletions
diff --git a/goprocnet_test.go b/goprocnet_test.go
new file mode 100644
index 0000000..734a22f
--- /dev/null
+++ b/goprocnet_test.go
@@ -0,0 +1,39 @@
+package goprocnet
+
+import (
+ "testing"
+)
+
+func TestTypeToFileMap(t *testing.T) {
+ result := getFilename("tcp")
+ if result != "/proc/net/tcp" {
+ t.Fail()
+ }
+ result = getFilename("udp")
+ if result != "/proc/net/udp" {
+ t.Fail()
+ }
+ result = getFilename("foobar")
+ if result != "" {
+ t.Fail()
+ }
+}
+
+func TestParseIPPort(t *testing.T) {
+ ip := getIP("00000000")
+ port := getPort("006F")
+ if ip != "0.0.0.0" {
+ t.Fail()
+ }
+ if port != "111" {
+ t.Fail()
+ }
+ ip = getIP("0B01010A")
+ if ip != "10.1.1.11" {
+ t.Fail()
+ }
+ port = getPort("CAEF")
+ if port != "51951" {
+ t.Fail()
+ }
+}