github.com/a4a881d4/docker@v1.9.0-rc2/pkg/ulimit/ulimit_test.go (about)

     1  package ulimit
     2  
     3  import "testing"
     4  
     5  func TestParseValid(t *testing.T) {
     6  	u1 := &Ulimit{"nofile", 1024, 512}
     7  	if u2, _ := Parse("nofile=512:1024"); *u1 != *u2 {
     8  		t.Fatalf("expected %q, but got %q", u1, u2)
     9  	}
    10  }
    11  
    12  func TestParseInvalidLimitType(t *testing.T) {
    13  	if _, err := Parse("notarealtype=1024:1024"); err == nil {
    14  		t.Fatalf("expected error on invalid ulimit type")
    15  	}
    16  }
    17  
    18  func TestParseBadFormat(t *testing.T) {
    19  	if _, err := Parse("nofile:1024:1024"); err == nil {
    20  		t.Fatal("expected error on bad syntax")
    21  	}
    22  
    23  	if _, err := Parse("nofile"); err == nil {
    24  		t.Fatal("expected error on bad syntax")
    25  	}
    26  
    27  	if _, err := Parse("nofile="); err == nil {
    28  		t.Fatal("expected error on bad syntax")
    29  	}
    30  	if _, err := Parse("nofile=:"); err == nil {
    31  		t.Fatal("expected error on bad syntax")
    32  	}
    33  	if _, err := Parse("nofile=:1024"); err == nil {
    34  		t.Fatal("expected error on bad syntax")
    35  	}
    36  }
    37  
    38  func TestParseHardLessThanSoft(t *testing.T) {
    39  	if _, err := Parse("nofile:1024:1"); err == nil {
    40  		t.Fatal("expected error on hard limit less than soft limit")
    41  	}
    42  }
    43  
    44  func TestParseInvalidValueType(t *testing.T) {
    45  	if _, err := Parse("nofile:asdf"); err == nil {
    46  		t.Fatal("expected error on bad value type")
    47  	}
    48  }
    49  
    50  func TestStringOutput(t *testing.T) {
    51  	u := &Ulimit{"nofile", 1024, 512}
    52  	if s := u.String(); s != "nofile=512:1024" {
    53  		t.Fatal("expected String to return nofile=512:1024, but got", s)
    54  	}
    55  }