github.com/dustinrc/deis@v1.10.1-0.20150917223407-0894a5fb979e/mesos/pkg/os/os_test.go (about)

     1  package os
     2  
     3  import (
     4  	"testing"
     5  )
     6  
     7  func TestGetoptEmpty(t *testing.T) {
     8  	value := Getopt("", "")
     9  	if value != "" {
    10  		t.Fatalf("Expected '' as value of empty env name but %s returned", value)
    11  	}
    12  }
    13  
    14  func TestGetoptValid(t *testing.T) {
    15  	value := Getopt("valid", "value")
    16  	if value != "value" {
    17  		t.Fatalf("Expected 'value' as value of 'valid' but %s returned", value)
    18  	}
    19  }
    20  
    21  func TestGetoptDefault(t *testing.T) {
    22  	value := Getopt("", "default")
    23  	if value != "default" {
    24  		t.Fatalf("Expected 'default' as value of empty env name but %s returned", value)
    25  	}
    26  }
    27  
    28  func TestBuildCommandFromStringSingle(t *testing.T) {
    29  	command, args := BuildCommandFromString("ls")
    30  	if command != "ls" {
    31  		t.Fatalf("Expected 'ls' as value of empty env name but %s returned", command)
    32  	}
    33  
    34  	if len(args) != 0 {
    35  		t.Fatalf("Expected '%v' arguments but %v returned", 0, len(args))
    36  	}
    37  
    38  	command, args = BuildCommandFromString("docker -d -D")
    39  	if command != "docker" {
    40  		t.Fatalf("Expected 'docker' as value of empty env name but %s returned", command)
    41  	}
    42  
    43  	if len(args) != 2 {
    44  		t.Fatalf("Expected '%v' arguments but %v returned", 0, len(args))
    45  	}
    46  
    47  	command, args = BuildCommandFromString("ls -lat")
    48  	if command != "ls" {
    49  		t.Fatalf("Expected 'ls' as value of empty env name but %s returned", command)
    50  	}
    51  
    52  	if len(args) != 1 {
    53  		t.Fatalf("Expected '%v' arguments but %v returned", 1, len(args))
    54  	}
    55  }
    56  
    57  func TestRandom(t *testing.T) {
    58  	rnd, err := Random(1)
    59  	if err != nil {
    60  		t.Fatal(err)
    61  	}
    62  
    63  	if len(rnd) != 1 {
    64  		t.Fatalf("Expected a string of 1 character but %s returned", rnd)
    65  	}
    66  }
    67  
    68  func TestRandomError(t *testing.T) {
    69  	rnd, err := Random(0)
    70  	if err == nil {
    71  		t.Fatalf("Expected an error requiring a random string of length 0 but %s returned", rnd)
    72  	}
    73  }