mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
More unit test fixes
- Fix TestGetImagesJSON when there is more than one image in the test repository; - Remove an hardcoded constant use in TestGetImagesByName; - Wait in a loop in TestKillDifferentUser; - Use env instead of /usr/bin/env in TestEnv; - Create a daemon user in contrib/mkimage-unittest.sh.
This commit is contained in:
parent
6f23e39e6b
commit
f03c1b8eeb
3 changed files with 19 additions and 10 deletions
13
api_test.go
13
api_test.go
|
@ -142,12 +142,13 @@ func TestGetImagesJSON(t *testing.T) {
|
||||||
|
|
||||||
srv := &Server{runtime: runtime}
|
srv := &Server{runtime: runtime}
|
||||||
|
|
||||||
initialImages, err := srv.Images(true, "")
|
// all=0
|
||||||
|
|
||||||
|
initialImages, err := srv.Images(false, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// all=0
|
|
||||||
req, err := http.NewRequest("GET", "/images/json?all=0", nil)
|
req, err := http.NewRequest("GET", "/images/json?all=0", nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
@ -182,6 +183,12 @@ func TestGetImagesJSON(t *testing.T) {
|
||||||
r2 := httptest.NewRecorder()
|
r2 := httptest.NewRecorder()
|
||||||
|
|
||||||
// all=1
|
// all=1
|
||||||
|
|
||||||
|
initialImages, err = srv.Images(true, "")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
req2, err := http.NewRequest("GET", "/images/json?all=true", nil)
|
req2, err := http.NewRequest("GET", "/images/json?all=true", nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
@ -352,7 +359,7 @@ func TestGetImagesByName(t *testing.T) {
|
||||||
if err := json.Unmarshal(r.Body.Bytes(), img); err != nil {
|
if err := json.Unmarshal(r.Body.Bytes(), img); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
if img.ID != GetTestImage(runtime).ID || img.Comment != "Imported from http://get.docker.io/images/busybox" {
|
if img.ID != unitTestImageId {
|
||||||
t.Errorf("Error inspecting image")
|
t.Errorf("Error inspecting image")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -511,12 +511,11 @@ func TestKillDifferentUser(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Give some time to lxc to spawn the process (setuid might take some time)
|
setTimeout(t, "Waiting for the container to be started timed out", 2 * time.Second, func() {
|
||||||
container.WaitTimeout(500 * time.Millisecond)
|
for !container.State.Running {
|
||||||
|
time.Sleep(10 * time.Millisecond)
|
||||||
if !container.State.Running {
|
}
|
||||||
t.Errorf("Container should be running")
|
})
|
||||||
}
|
|
||||||
|
|
||||||
if err := container.Kill(); err != nil {
|
if err := container.Kill(); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
@ -1001,7 +1000,7 @@ func TestEnv(t *testing.T) {
|
||||||
defer nuke(runtime)
|
defer nuke(runtime)
|
||||||
container, err := NewBuilder(runtime).Create(&Config{
|
container, err := NewBuilder(runtime).Create(&Config{
|
||||||
Image: GetTestImage(runtime).ID,
|
Image: GetTestImage(runtime).ID,
|
||||||
Cmd: []string{"/usr/bin/env"},
|
Cmd: []string{"env"},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -23,7 +23,9 @@ mkdir bin etc dev dev/pts lib proc sys tmp
|
||||||
touch etc/resolv.conf
|
touch etc/resolv.conf
|
||||||
cp /etc/nsswitch.conf etc/nsswitch.conf
|
cp /etc/nsswitch.conf etc/nsswitch.conf
|
||||||
echo root:x:0:0:root:/:/bin/sh > etc/passwd
|
echo root:x:0:0:root:/:/bin/sh > etc/passwd
|
||||||
|
echo daemon:x:1:1:daemon:/usr/sbin:/bin/sh >> etc/passwd
|
||||||
echo root:x:0: > etc/group
|
echo root:x:0: > etc/group
|
||||||
|
echo daemon:x:1: >> etc/group
|
||||||
ln -s lib lib64
|
ln -s lib lib64
|
||||||
ln -s bin sbin
|
ln -s bin sbin
|
||||||
cp $BUSYBOX $SOCAT bin
|
cp $BUSYBOX $SOCAT bin
|
||||||
|
@ -41,6 +43,7 @@ do
|
||||||
cp -a /dev/$X dev
|
cp -a /dev/$X dev
|
||||||
done
|
done
|
||||||
|
|
||||||
|
chmod 0755 $ROOTFS # See #486
|
||||||
tar -cf- . | docker import - docker-ut
|
tar -cf- . | docker import - docker-ut
|
||||||
docker run -i -u root docker-ut /bin/echo Success.
|
docker run -i -u root docker-ut /bin/echo Success.
|
||||||
rm -rf $ROOTFS
|
rm -rf $ROOTFS
|
||||||
|
|
Loading…
Add table
Reference in a new issue