github.com/fcwu/docker@v1.4.2-0.20150115145920-2a69ca89f0df/daemon/utils_test.go (about)

     1  package daemon
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/docker/docker/runconfig"
     7  	"github.com/docker/docker/utils"
     8  )
     9  
    10  func TestMergeLxcConfig(t *testing.T) {
    11  	hostConfig := &runconfig.HostConfig{
    12  		LxcConf: []utils.KeyValuePair{
    13  			{Key: "lxc.cgroups.cpuset", Value: "1,2"},
    14  		},
    15  	}
    16  
    17  	out, err := mergeLxcConfIntoOptions(hostConfig)
    18  	if err != nil {
    19  		t.Fatalf("Failed to merge Lxc Config: %s", err)
    20  	}
    21  
    22  	cpuset := out[0]
    23  	if expected := "cgroups.cpuset=1,2"; cpuset != expected {
    24  		t.Fatalf("expected %s got %s", expected, cpuset)
    25  	}
    26  }
    27  
    28  func TestRemoveLocalDns(t *testing.T) {
    29  	ns0 := "nameserver 10.16.60.14\nnameserver 10.16.60.21\n"
    30  
    31  	if result := utils.RemoveLocalDns([]byte(ns0)); result != nil {
    32  		if ns0 != string(result) {
    33  			t.Fatalf("Failed No Localhost: expected \n<%s> got \n<%s>", ns0, string(result))
    34  		}
    35  	}
    36  
    37  	ns1 := "nameserver 10.16.60.14\nnameserver 10.16.60.21\nnameserver 127.0.0.1\n"
    38  	if result := utils.RemoveLocalDns([]byte(ns1)); result != nil {
    39  		if ns0 != string(result) {
    40  			t.Fatalf("Failed Localhost: expected \n<%s> got \n<%s>", ns0, string(result))
    41  		}
    42  	}
    43  
    44  	ns1 = "nameserver 10.16.60.14\nnameserver 127.0.0.1\nnameserver 10.16.60.21\n"
    45  	if result := utils.RemoveLocalDns([]byte(ns1)); result != nil {
    46  		if ns0 != string(result) {
    47  			t.Fatalf("Failed Localhost: expected \n<%s> got \n<%s>", ns0, string(result))
    48  		}
    49  	}
    50  
    51  	ns1 = "nameserver 127.0.1.1\nnameserver 10.16.60.14\nnameserver 10.16.60.21\n"
    52  	if result := utils.RemoveLocalDns([]byte(ns1)); result != nil {
    53  		if ns0 != string(result) {
    54  			t.Fatalf("Failed Localhost: expected \n<%s> got \n<%s>", ns0, string(result))
    55  		}
    56  	}
    57  }