mirror of
https://github.com/weaveworks/scope.git
synced 2026-03-05 11:11:13 +00:00
This caused a dependency chain reaction (sigh):
* All the k8s packages had to be fetched again. This in turn required:
* Pining github.com/docker/docker/pkg/parsers to
0f5c9d301b9b1cca66b3ea0f9dec3b5317d3686d to cirvumvent
https://github.com/kubernetes/kubernetes/issues/18774
* Update github.com/juju/ratelimit
* Make probe/kubernetes/client.go comply with API changes.
75 lines
2.0 KiB
Go
75 lines
2.0 KiB
Go
package units
|
|
|
|
import (
|
|
"fmt"
|
|
"strconv"
|
|
"testing"
|
|
)
|
|
|
|
func ExampleParseUlimit() {
|
|
fmt.Println(ParseUlimit("nofile=512:1024"))
|
|
fmt.Println(ParseUlimit("nofile=1024"))
|
|
fmt.Println(ParseUlimit("cpu=2:4"))
|
|
fmt.Println(ParseUlimit("cpu=6"))
|
|
}
|
|
|
|
func TestParseUlimitValid(t *testing.T) {
|
|
u1 := &Ulimit{"nofile", 1024, 512}
|
|
if u2, _ := ParseUlimit("nofile=512:1024"); *u1 != *u2 {
|
|
t.Fatalf("expected %q, but got %q", u1, u2)
|
|
}
|
|
}
|
|
|
|
func TestParseUlimitInvalidLimitType(t *testing.T) {
|
|
if _, err := ParseUlimit("notarealtype=1024:1024"); err == nil {
|
|
t.Fatalf("expected error on invalid ulimit type")
|
|
}
|
|
}
|
|
|
|
func TestParseUlimitBadFormat(t *testing.T) {
|
|
if _, err := ParseUlimit("nofile:1024:1024"); err == nil {
|
|
t.Fatal("expected error on bad syntax")
|
|
}
|
|
|
|
if _, err := ParseUlimit("nofile"); err == nil {
|
|
t.Fatal("expected error on bad syntax")
|
|
}
|
|
|
|
if _, err := ParseUlimit("nofile="); err == nil {
|
|
t.Fatal("expected error on bad syntax")
|
|
}
|
|
if _, err := ParseUlimit("nofile=:"); err == nil {
|
|
t.Fatal("expected error on bad syntax")
|
|
}
|
|
if _, err := ParseUlimit("nofile=:1024"); err == nil {
|
|
t.Fatal("expected error on bad syntax")
|
|
}
|
|
}
|
|
|
|
func TestParseUlimitHardLessThanSoft(t *testing.T) {
|
|
if _, err := ParseUlimit("nofile=1024:1"); err == nil {
|
|
t.Fatal("expected error on hard limit less than soft limit")
|
|
}
|
|
}
|
|
|
|
func TestParseUlimitInvalidValueType(t *testing.T) {
|
|
if _, err := ParseUlimit("nofile=asdf"); err == nil {
|
|
t.Fatal("expected error on bad value type, but got no error")
|
|
} else if _, ok := err.(*strconv.NumError); !ok {
|
|
t.Fatalf("expected error on bad value type, but got `%s`", err)
|
|
}
|
|
|
|
if _, err := ParseUlimit("nofile=1024:asdf"); err == nil {
|
|
t.Fatal("expected error on bad value type, but got no error")
|
|
} else if _, ok := err.(*strconv.NumError); !ok {
|
|
t.Fatalf("expected error on bad value type, but got `%s`", err)
|
|
}
|
|
}
|
|
|
|
func TestUlimitStringOutput(t *testing.T) {
|
|
u := &Ulimit{"nofile", 1024, 512}
|
|
if s := u.String(); s != "nofile=512:1024" {
|
|
t.Fatal("expected String to return nofile=512:1024, but got", s)
|
|
}
|
|
}
|