github.com/rentongzhang/docker@v1.8.2-rc1/api/server/server_linux_test.go (about)

     1  // +build linux
     2  
     3  package server
     4  
     5  import (
     6  	"testing"
     7  
     8  	"github.com/docker/docker/pkg/version"
     9  	"github.com/docker/docker/runconfig"
    10  )
    11  
    12  func TestAdjustCpuSharesOldApi(t *testing.T) {
    13  	apiVersion := version.Version("1.18")
    14  	hostConfig := &runconfig.HostConfig{
    15  		CpuShares: linuxMinCpuShares - 1,
    16  	}
    17  	adjustCpuShares(apiVersion, hostConfig)
    18  	if hostConfig.CpuShares != linuxMinCpuShares {
    19  		t.Errorf("Expected CpuShares to be %d", linuxMinCpuShares)
    20  	}
    21  
    22  	hostConfig.CpuShares = linuxMaxCpuShares + 1
    23  	adjustCpuShares(apiVersion, hostConfig)
    24  	if hostConfig.CpuShares != linuxMaxCpuShares {
    25  		t.Errorf("Expected CpuShares to be %d", linuxMaxCpuShares)
    26  	}
    27  
    28  	hostConfig.CpuShares = 0
    29  	adjustCpuShares(apiVersion, hostConfig)
    30  	if hostConfig.CpuShares != 0 {
    31  		t.Error("Expected CpuShares to be unchanged")
    32  	}
    33  
    34  	hostConfig.CpuShares = 1024
    35  	adjustCpuShares(apiVersion, hostConfig)
    36  	if hostConfig.CpuShares != 1024 {
    37  		t.Error("Expected CpuShares to be unchanged")
    38  	}
    39  }
    40  
    41  func TestAdjustCpuSharesNoAdjustment(t *testing.T) {
    42  	apiVersion := version.Version("1.19")
    43  	hostConfig := &runconfig.HostConfig{
    44  		CpuShares: linuxMinCpuShares - 1,
    45  	}
    46  	adjustCpuShares(apiVersion, hostConfig)
    47  	if hostConfig.CpuShares != linuxMinCpuShares-1 {
    48  		t.Errorf("Expected CpuShares to be %d", linuxMinCpuShares-1)
    49  	}
    50  
    51  	hostConfig.CpuShares = linuxMaxCpuShares + 1
    52  	adjustCpuShares(apiVersion, hostConfig)
    53  	if hostConfig.CpuShares != linuxMaxCpuShares+1 {
    54  		t.Errorf("Expected CpuShares to be %d", linuxMaxCpuShares+1)
    55  	}
    56  
    57  	hostConfig.CpuShares = 0
    58  	adjustCpuShares(apiVersion, hostConfig)
    59  	if hostConfig.CpuShares != 0 {
    60  		t.Error("Expected CpuShares to be unchanged")
    61  	}
    62  
    63  	hostConfig.CpuShares = 1024
    64  	adjustCpuShares(apiVersion, hostConfig)
    65  	if hostConfig.CpuShares != 1024 {
    66  		t.Error("Expected CpuShares to be unchanged")
    67  	}
    68  }