| 18 | ) |
| 19 | |
| 20 | func TestNetStat(t *testing.T) { |
| 21 | const ( |
| 22 | filesCount = 2 |
| 23 | CPUsCount = 2 |
| 24 | arpCacheMetricsCount = 13 |
| 25 | ndiscCacheMetricsCount = 13 |
| 26 | ) |
| 27 | |
| 28 | fs, err := NewFS(procTestFixtures) |
| 29 | if err != nil { |
| 30 | t.Fatalf("failed to open procfs: %v", err) |
| 31 | } |
| 32 | |
| 33 | netStats, err := fs.NetStat() |
| 34 | if err != nil { |
| 35 | t.Fatalf("NetStat() error: %s", err) |
| 36 | } |
| 37 | |
| 38 | if len(netStats) != filesCount { |
| 39 | t.Fatalf("unexpected number of files parsed %d, expected %d", len(netStats), filesCount) |
| 40 | } |
| 41 | |
| 42 | expectedStats := [2]NetStat{ |
| 43 | { |
| 44 | Filename: "arp_cache", |
| 45 | Stats: make(map[string][]uint64), |
| 46 | }, |
| 47 | { |
| 48 | Filename: "ndisc_cache", |
| 49 | Stats: make(map[string][]uint64), |
| 50 | }, |
| 51 | } |
| 52 | |
| 53 | for _, expected := range expectedStats { |
| 54 | if expected.Filename == "arp_cache" { |
| 55 | expected.Stats["entries"] = []uint64{20, 20} |
| 56 | expected.Stats["allocs"] = []uint64{1, 13} |
| 57 | expected.Stats["destroys"] = []uint64{2, 14} |
| 58 | expected.Stats["hash_grows"] = []uint64{3, 15} |
| 59 | expected.Stats["lookups"] = []uint64{4, 16} |
| 60 | expected.Stats["hits"] = []uint64{5, 17} |
| 61 | expected.Stats["res_failed"] = []uint64{6, 18} |
| 62 | expected.Stats["rcv_probes_mcast"] = []uint64{7, 19} |
| 63 | expected.Stats["rcv_probes_ucast"] = []uint64{8, 20} |
| 64 | expected.Stats["periodic_gc_runs"] = []uint64{9, 21} |
| 65 | expected.Stats["forced_gc_runs"] = []uint64{10, 22} |
| 66 | expected.Stats["unresolved_discards"] = []uint64{11, 23} |
| 67 | expected.Stats["table_fulls"] = []uint64{12, 24} |
| 68 | } |
| 69 | if expected.Filename == "ndisc_cache" { |
| 70 | expected.Stats["entries"] = []uint64{36, 36} |
| 71 | expected.Stats["allocs"] = []uint64{240, 252} |
| 72 | expected.Stats["destroys"] = []uint64{241, 253} |
| 73 | expected.Stats["hash_grows"] = []uint64{242, 254} |
| 74 | expected.Stats["lookups"] = []uint64{243, 255} |
| 75 | expected.Stats["hits"] = []uint64{244, 256} |
| 76 | expected.Stats["res_failed"] = []uint64{245, 257} |
| 77 | expected.Stats["rcv_probes_mcast"] = []uint64{246, 258} |