github.com/sams1990/dockerrepo@v17.12.1-ce-rc2+incompatible/container/container_unit_test.go (about)

     1  package container
     2  
     3  import (
     4  	"path/filepath"
     5  	"testing"
     6  
     7  	"github.com/docker/docker/api/types/container"
     8  	swarmtypes "github.com/docker/docker/api/types/swarm"
     9  	"github.com/docker/docker/pkg/signal"
    10  )
    11  
    12  func TestContainerStopSignal(t *testing.T) {
    13  	c := &Container{
    14  		Config: &container.Config{},
    15  	}
    16  
    17  	def, err := signal.ParseSignal(signal.DefaultStopSignal)
    18  	if err != nil {
    19  		t.Fatal(err)
    20  	}
    21  
    22  	s := c.StopSignal()
    23  	if s != int(def) {
    24  		t.Fatalf("Expected %v, got %v", def, s)
    25  	}
    26  
    27  	c = &Container{
    28  		Config: &container.Config{StopSignal: "SIGKILL"},
    29  	}
    30  	s = c.StopSignal()
    31  	if s != 9 {
    32  		t.Fatalf("Expected 9, got %v", s)
    33  	}
    34  }
    35  
    36  func TestContainerStopTimeout(t *testing.T) {
    37  	c := &Container{
    38  		Config: &container.Config{},
    39  	}
    40  
    41  	s := c.StopTimeout()
    42  	if s != DefaultStopTimeout {
    43  		t.Fatalf("Expected %v, got %v", DefaultStopTimeout, s)
    44  	}
    45  
    46  	stopTimeout := 15
    47  	c = &Container{
    48  		Config: &container.Config{StopTimeout: &stopTimeout},
    49  	}
    50  	s = c.StopSignal()
    51  	if s != 15 {
    52  		t.Fatalf("Expected 15, got %v", s)
    53  	}
    54  }
    55  
    56  func TestContainerSecretReferenceDestTarget(t *testing.T) {
    57  	ref := &swarmtypes.SecretReference{
    58  		File: &swarmtypes.SecretReferenceFileTarget{
    59  			Name: "app",
    60  		},
    61  	}
    62  
    63  	d := getSecretTargetPath(ref)
    64  	expected := filepath.Join(containerSecretMountPath, "app")
    65  	if d != expected {
    66  		t.Fatalf("expected secret dest %q; received %q", expected, d)
    67  	}
    68  }