summaryrefslogtreecommitdiff
path: root/goprocnet_test.go
blob: 734a22f5ed7c53e1617822c6bd03832425ce9024 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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()
	}
}