mirror of
https://github.com/clearlinux/docker.git
synced 2026-10-03 23:38:24 +00:00
Merge master within fs
This commit is contained in:
+62
-6
@@ -2,9 +2,12 @@ package docker
|
||||
|
||||
import (
|
||||
"./fs"
|
||||
"bufio"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"math/rand"
|
||||
"os"
|
||||
"sort"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -23,7 +26,7 @@ func TestCommitRun(t *testing.T) {
|
||||
[]string{"-c", "echo hello > /world"},
|
||||
GetTestImage(docker),
|
||||
&Config{
|
||||
Ram: 33554432,
|
||||
Memory: 33554432,
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
@@ -65,7 +68,7 @@ func TestCommitRun(t *testing.T) {
|
||||
[]string{"/world"},
|
||||
img,
|
||||
&Config{
|
||||
Ram: 33554432,
|
||||
Memory: 33554432,
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
@@ -100,7 +103,7 @@ func TestRun(t *testing.T) {
|
||||
[]string{"-al"},
|
||||
GetTestImage(docker),
|
||||
&Config{
|
||||
Ram: 33554432,
|
||||
Memory: 33554432,
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
@@ -349,7 +352,7 @@ func TestUser(t *testing.T) {
|
||||
// Set a username
|
||||
container, err = docker.Create(
|
||||
"user_root",
|
||||
"/bin/id",
|
||||
"id",
|
||||
[]string{},
|
||||
GetTestImage(docker),
|
||||
&Config{
|
||||
@@ -393,7 +396,7 @@ func TestUser(t *testing.T) {
|
||||
// Set a different user by uid
|
||||
container, err = docker.Create(
|
||||
"user_uid1",
|
||||
"/usr/bin/id",
|
||||
"id",
|
||||
[]string{},
|
||||
GetTestImage(docker),
|
||||
&Config{
|
||||
@@ -417,7 +420,7 @@ func TestUser(t *testing.T) {
|
||||
// Set a different user by username
|
||||
container, err = docker.Create(
|
||||
"user_daemon",
|
||||
"/usr/bin/id",
|
||||
"id",
|
||||
[]string{},
|
||||
GetTestImage(docker),
|
||||
&Config{
|
||||
@@ -616,6 +619,59 @@ func TestEnv(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func grepFile(t *testing.T, path string, pattern string) {
|
||||
f, err := os.Open(path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer f.Close()
|
||||
r := bufio.NewReader(f)
|
||||
var (
|
||||
line string
|
||||
)
|
||||
err = nil
|
||||
for err == nil {
|
||||
line, err = r.ReadString('\n')
|
||||
if strings.Contains(line, pattern) == true {
|
||||
return
|
||||
}
|
||||
}
|
||||
t.Fatalf("grepFile: pattern \"%s\" not found in \"%s\"", pattern, path)
|
||||
}
|
||||
|
||||
func TestLXCConfig(t *testing.T) {
|
||||
docker, err := newTestDocker()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer nuke(docker)
|
||||
// Memory is allocated randomly for testing
|
||||
rand.Seed(time.Now().UTC().UnixNano())
|
||||
memMin := 33554432
|
||||
memMax := 536870912
|
||||
mem := memMin + rand.Intn(memMax-memMin)
|
||||
container, err := docker.Create(
|
||||
"config_test",
|
||||
"/bin/true",
|
||||
[]string{},
|
||||
GetTestImage(docker),
|
||||
&Config{
|
||||
Hostname: "foobar",
|
||||
Memory: int64(mem),
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer docker.Destroy(container)
|
||||
container.generateLXCConfig()
|
||||
grepFile(t, container.lxcConfigPath, "lxc.utsname = foobar")
|
||||
grepFile(t, container.lxcConfigPath,
|
||||
fmt.Sprintf("lxc.cgroup.memory.limit_in_bytes = %d", mem))
|
||||
grepFile(t, container.lxcConfigPath,
|
||||
fmt.Sprintf("lxc.cgroup.memory.memsw.limit_in_bytes = %d", mem*2))
|
||||
}
|
||||
|
||||
func BenchmarkRunSequencial(b *testing.B) {
|
||||
docker, err := newTestDocker()
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user