1// Copyright 2019 The Prometheus Authors
2// Licensed under the Apache License, Version 2.0 (the "License");
3// you may not use this file except in compliance with the License.
4// You may obtain a copy of the License at
5//
6// http://www.apache.org/licenses/LICENSE-2.0
7//
8// Unless required by applicable law or agreed to in writing, software
9// distributed under the License is distributed on an "AS IS" BASIS,
10// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11// See the License for the specific language governing permissions and
12// limitations under the License.
13
14package procfs
15
16import (
17	"testing"
18
19	"github.com/google/go-cmp/cmp"
20)
21
22func TestNetSoftnet(t *testing.T) {
23	fs, err := NewFS(procTestFixtures)
24	if err != nil {
25		t.Fatal(err)
26	}
27
28	want := []SoftnetStat{{
29		Processed:    0x00015c73,
30		Dropped:      0x00020e76,
31		TimeSqueezed: 0xf0000769,
32	},
33		{
34			Processed:    0x01663fb2,
35			TimeSqueezed: 0x0109a4,
36		}}
37
38	got, err := fs.NetSoftnetStat()
39	if err != nil {
40		t.Fatal(err)
41	}
42
43	if diff := cmp.Diff(want, got); diff != "" {
44		t.Fatalf("unexpected softnet stats(-want +got):\n%s", diff)
45	}
46}
47
48func TestBadSoftnet(t *testing.T) {
49	softNetProcFile = "net/softnet_stat.broken"
50	fs, err := NewFS(procTestFixtures)
51	if err != nil {
52		t.Fatal(err)
53	}
54
55	_, err = fs.NetSoftnetStat()
56	if err == nil {
57		t.Fatal("expected error, got nil")
58	}
59}
60