2021-02-04 17:10:10 +03:00
|
|
|
package metrics
|
|
|
|
|
|
|
|
import "testing"
|
|
|
|
|
2021-02-04 17:28:55 +03:00
|
|
|
func TestGetMaxFilesLimit(t *testing.T) {
|
|
|
|
f := func(want uint64, path string, wantErr bool) {
|
2021-02-04 17:10:10 +03:00
|
|
|
t.Helper()
|
|
|
|
got, err := getMaxFilesLimit(path)
|
|
|
|
if err != nil && !wantErr {
|
2021-02-04 17:28:55 +03:00
|
|
|
t.Fatalf("unexpected error: %v", err)
|
2021-02-04 17:10:10 +03:00
|
|
|
}
|
2021-02-04 17:28:55 +03:00
|
|
|
if got != want {
|
|
|
|
t.Fatalf("unexpected result: %d, want: %d at getMaxFilesLimit", got, want)
|
2021-02-04 17:10:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2021-02-04 17:28:55 +03:00
|
|
|
f(1024, "testdata/limits", false)
|
|
|
|
f(0, "testdata/bad_path", true)
|
|
|
|
f(0, "testdata/limits_bad", true)
|
2021-02-04 17:10:10 +03:00
|
|
|
}
|
|
|
|
|
2021-02-04 17:28:55 +03:00
|
|
|
func TestGetOpenFDsCount(t *testing.T) {
|
|
|
|
f := func(want uint64, path string, wantErr bool) {
|
2021-02-04 17:10:10 +03:00
|
|
|
t.Helper()
|
|
|
|
got, err := getOpenFDsCount(path)
|
2021-02-04 17:28:55 +03:00
|
|
|
if (err != nil && !wantErr) || (err == nil && wantErr) {
|
|
|
|
t.Fatalf("unexpected error: %v", err)
|
2021-02-04 17:10:10 +03:00
|
|
|
}
|
2021-02-04 17:28:55 +03:00
|
|
|
if got != want {
|
|
|
|
t.Fatalf("unexpected result: %d, want: %d at getOpenFDsCount", got, want)
|
2021-02-04 17:10:10 +03:00
|
|
|
}
|
|
|
|
}
|
2021-02-04 17:28:55 +03:00
|
|
|
f(5, "testdata/fd/", false)
|
|
|
|
f(0, "testdata/fd/0", true)
|
|
|
|
f(0, "testdata/limits", true)
|
2021-02-04 17:10:10 +03:00
|
|
|
}
|