Signed-off-by: John Howard <jhoward@microsoft.com>
| ... | ... |
@@ -133,72 +133,6 @@ func initDaemonWithVolumeStore(tmp string) (*Daemon, error) {
|
| 133 | 133 |
return daemon, nil |
| 134 | 134 |
} |
| 135 | 135 |
|
| 136 |
-func TestParseSecurityOpt(t *testing.T) {
|
|
| 137 |
- container := &container.Container{}
|
|
| 138 |
- config := &containertypes.HostConfig{}
|
|
| 139 |
- |
|
| 140 |
- // test apparmor |
|
| 141 |
- config.SecurityOpt = []string{"apparmor:test_profile"}
|
|
| 142 |
- if err := parseSecurityOpt(container, config); err != nil {
|
|
| 143 |
- t.Fatalf("Unexpected parseSecurityOpt error: %v", err)
|
|
| 144 |
- } |
|
| 145 |
- if container.AppArmorProfile != "test_profile" {
|
|
| 146 |
- t.Fatalf("Unexpected AppArmorProfile, expected: \"test_profile\", got %q", container.AppArmorProfile)
|
|
| 147 |
- } |
|
| 148 |
- |
|
| 149 |
- // test seccomp |
|
| 150 |
- sp := "/path/to/seccomp_test.json" |
|
| 151 |
- config.SecurityOpt = []string{"seccomp:" + sp}
|
|
| 152 |
- if err := parseSecurityOpt(container, config); err != nil {
|
|
| 153 |
- t.Fatalf("Unexpected parseSecurityOpt error: %v", err)
|
|
| 154 |
- } |
|
| 155 |
- if container.SeccompProfile != sp {
|
|
| 156 |
- t.Fatalf("Unexpected AppArmorProfile, expected: %q, got %q", sp, container.SeccompProfile)
|
|
| 157 |
- } |
|
| 158 |
- |
|
| 159 |
- // test valid label |
|
| 160 |
- config.SecurityOpt = []string{"label:user:USER"}
|
|
| 161 |
- if err := parseSecurityOpt(container, config); err != nil {
|
|
| 162 |
- t.Fatalf("Unexpected parseSecurityOpt error: %v", err)
|
|
| 163 |
- } |
|
| 164 |
- |
|
| 165 |
- // test invalid label |
|
| 166 |
- config.SecurityOpt = []string{"label"}
|
|
| 167 |
- if err := parseSecurityOpt(container, config); err == nil {
|
|
| 168 |
- t.Fatal("Expected parseSecurityOpt error, got nil")
|
|
| 169 |
- } |
|
| 170 |
- |
|
| 171 |
- // test invalid opt |
|
| 172 |
- config.SecurityOpt = []string{"test"}
|
|
| 173 |
- if err := parseSecurityOpt(container, config); err == nil {
|
|
| 174 |
- t.Fatal("Expected parseSecurityOpt error, got nil")
|
|
| 175 |
- } |
|
| 176 |
-} |
|
| 177 |
- |
|
| 178 |
-func TestNetworkOptions(t *testing.T) {
|
|
| 179 |
- daemon := &Daemon{}
|
|
| 180 |
- dconfigCorrect := &Config{
|
|
| 181 |
- CommonConfig: CommonConfig{
|
|
| 182 |
- ClusterStore: "consul://localhost:8500", |
|
| 183 |
- ClusterAdvertise: "192.168.0.1:8000", |
|
| 184 |
- }, |
|
| 185 |
- } |
|
| 186 |
- |
|
| 187 |
- if _, err := daemon.networkOptions(dconfigCorrect); err != nil {
|
|
| 188 |
- t.Fatalf("Expect networkOptions sucess, got error: %v", err)
|
|
| 189 |
- } |
|
| 190 |
- |
|
| 191 |
- dconfigWrong := &Config{
|
|
| 192 |
- CommonConfig: CommonConfig{
|
|
| 193 |
- ClusterStore: "consul://localhost:8500://test://bbb", |
|
| 194 |
- }, |
|
| 195 |
- } |
|
| 196 |
- |
|
| 197 |
- if _, err := daemon.networkOptions(dconfigWrong); err == nil {
|
|
| 198 |
- t.Fatalf("Expected networkOptions error, got nil")
|
|
| 199 |
- } |
|
| 200 |
-} |
|
| 201 |
- |
|
| 202 | 136 |
func TestValidContainerNames(t *testing.T) {
|
| 203 | 137 |
invalidNames := []string{"-rm", "&sdfsfd", "safd%sd"}
|
| 204 | 138 |
validNames := []string{"word-word", "word_word", "1weoid"}
|
| ... | ... |
@@ -7,9 +7,11 @@ import ( |
| 7 | 7 |
"os" |
| 8 | 8 |
"testing" |
| 9 | 9 |
|
| 10 |
- "github.com/docker/engine-api/types/container" |
|
| 10 |
+ "github.com/docker/docker/container" |
|
| 11 |
+ containertypes "github.com/docker/engine-api/types/container" |
|
| 11 | 12 |
) |
| 12 | 13 |
|
| 14 |
+// Unix test as uses settings which are not available on Windows |
|
| 13 | 15 |
func TestAdjustCPUShares(t *testing.T) {
|
| 14 | 16 |
tmp, err := ioutil.TempDir("", "docker-daemon-unix-test-")
|
| 15 | 17 |
if err != nil {
|
| ... | ... |
@@ -21,8 +23,8 @@ func TestAdjustCPUShares(t *testing.T) {
|
| 21 | 21 |
root: tmp, |
| 22 | 22 |
} |
| 23 | 23 |
|
| 24 |
- hostConfig := &container.HostConfig{
|
|
| 25 |
- Resources: container.Resources{CPUShares: linuxMinCPUShares - 1},
|
|
| 24 |
+ hostConfig := &containertypes.HostConfig{
|
|
| 25 |
+ Resources: containertypes.Resources{CPUShares: linuxMinCPUShares - 1},
|
|
| 26 | 26 |
} |
| 27 | 27 |
daemon.adaptContainerSettings(hostConfig, true) |
| 28 | 28 |
if hostConfig.CPUShares != linuxMinCPUShares {
|
| ... | ... |
@@ -48,6 +50,7 @@ func TestAdjustCPUShares(t *testing.T) {
|
| 48 | 48 |
} |
| 49 | 49 |
} |
| 50 | 50 |
|
| 51 |
+// Unix test as uses settings which are not available on Windows |
|
| 51 | 52 |
func TestAdjustCPUSharesNoAdjustment(t *testing.T) {
|
| 52 | 53 |
tmp, err := ioutil.TempDir("", "docker-daemon-unix-test-")
|
| 53 | 54 |
if err != nil {
|
| ... | ... |
@@ -59,8 +62,8 @@ func TestAdjustCPUSharesNoAdjustment(t *testing.T) {
|
| 59 | 59 |
root: tmp, |
| 60 | 60 |
} |
| 61 | 61 |
|
| 62 |
- hostConfig := &container.HostConfig{
|
|
| 63 |
- Resources: container.Resources{CPUShares: linuxMinCPUShares - 1},
|
|
| 62 |
+ hostConfig := &containertypes.HostConfig{
|
|
| 63 |
+ Resources: containertypes.Resources{CPUShares: linuxMinCPUShares - 1},
|
|
| 64 | 64 |
} |
| 65 | 65 |
daemon.adaptContainerSettings(hostConfig, false) |
| 66 | 66 |
if hostConfig.CPUShares != linuxMinCPUShares-1 {
|
| ... | ... |
@@ -85,3 +88,70 @@ func TestAdjustCPUSharesNoAdjustment(t *testing.T) {
|
| 85 | 85 |
t.Error("Expected CPUShares to be unchanged")
|
| 86 | 86 |
} |
| 87 | 87 |
} |
| 88 |
+ |
|
| 89 |
+// Unix test as uses settings which are not available on Windows |
|
| 90 |
+func TestParseSecurityOpt(t *testing.T) {
|
|
| 91 |
+ container := &container.Container{}
|
|
| 92 |
+ config := &containertypes.HostConfig{}
|
|
| 93 |
+ |
|
| 94 |
+ // test apparmor |
|
| 95 |
+ config.SecurityOpt = []string{"apparmor:test_profile"}
|
|
| 96 |
+ if err := parseSecurityOpt(container, config); err != nil {
|
|
| 97 |
+ t.Fatalf("Unexpected parseSecurityOpt error: %v", err)
|
|
| 98 |
+ } |
|
| 99 |
+ if container.AppArmorProfile != "test_profile" {
|
|
| 100 |
+ t.Fatalf("Unexpected AppArmorProfile, expected: \"test_profile\", got %q", container.AppArmorProfile)
|
|
| 101 |
+ } |
|
| 102 |
+ |
|
| 103 |
+ // test seccomp |
|
| 104 |
+ sp := "/path/to/seccomp_test.json" |
|
| 105 |
+ config.SecurityOpt = []string{"seccomp:" + sp}
|
|
| 106 |
+ if err := parseSecurityOpt(container, config); err != nil {
|
|
| 107 |
+ t.Fatalf("Unexpected parseSecurityOpt error: %v", err)
|
|
| 108 |
+ } |
|
| 109 |
+ if container.SeccompProfile != sp {
|
|
| 110 |
+ t.Fatalf("Unexpected AppArmorProfile, expected: %q, got %q", sp, container.SeccompProfile)
|
|
| 111 |
+ } |
|
| 112 |
+ |
|
| 113 |
+ // test valid label |
|
| 114 |
+ config.SecurityOpt = []string{"label:user:USER"}
|
|
| 115 |
+ if err := parseSecurityOpt(container, config); err != nil {
|
|
| 116 |
+ t.Fatalf("Unexpected parseSecurityOpt error: %v", err)
|
|
| 117 |
+ } |
|
| 118 |
+ |
|
| 119 |
+ // test invalid label |
|
| 120 |
+ config.SecurityOpt = []string{"label"}
|
|
| 121 |
+ if err := parseSecurityOpt(container, config); err == nil {
|
|
| 122 |
+ t.Fatal("Expected parseSecurityOpt error, got nil")
|
|
| 123 |
+ } |
|
| 124 |
+ |
|
| 125 |
+ // test invalid opt |
|
| 126 |
+ config.SecurityOpt = []string{"test"}
|
|
| 127 |
+ if err := parseSecurityOpt(container, config); err == nil {
|
|
| 128 |
+ t.Fatal("Expected parseSecurityOpt error, got nil")
|
|
| 129 |
+ } |
|
| 130 |
+} |
|
| 131 |
+ |
|
| 132 |
+func TestNetworkOptions(t *testing.T) {
|
|
| 133 |
+ daemon := &Daemon{}
|
|
| 134 |
+ dconfigCorrect := &Config{
|
|
| 135 |
+ CommonConfig: CommonConfig{
|
|
| 136 |
+ ClusterStore: "consul://localhost:8500", |
|
| 137 |
+ ClusterAdvertise: "192.168.0.1:8000", |
|
| 138 |
+ }, |
|
| 139 |
+ } |
|
| 140 |
+ |
|
| 141 |
+ if _, err := daemon.networkOptions(dconfigCorrect); err != nil {
|
|
| 142 |
+ t.Fatalf("Expect networkOptions sucess, got error: %v", err)
|
|
| 143 |
+ } |
|
| 144 |
+ |
|
| 145 |
+ dconfigWrong := &Config{
|
|
| 146 |
+ CommonConfig: CommonConfig{
|
|
| 147 |
+ ClusterStore: "consul://localhost:8500://test://bbb", |
|
| 148 |
+ }, |
|
| 149 |
+ } |
|
| 150 |
+ |
|
| 151 |
+ if _, err := daemon.networkOptions(dconfigWrong); err == nil {
|
|
| 152 |
+ t.Fatalf("Expected networkOptions error, got nil")
|
|
| 153 |
+ } |
|
| 154 |
+} |