-
Notifications
You must be signed in to change notification settings - Fork 0
/
image_test.go
85 lines (70 loc) · 1.65 KB
/
image_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package main
import (
log "github.com/Sirupsen/logrus"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/client"
"github.com/stretchr/testify/assert"
"os"
"testing"
)
var image *dockerImage
func init() {
os.Setenv("DOCKER_API_VERSION", "1.24")
client, err := client.NewEnvClient()
if err != nil {
panic(err)
}
image = NewDockerImage(client)
}
func TestListImages(t *testing.T) {
os.Setenv("DOCKER_API_VERSION", "1.24")
client, _ := client.NewEnvClient()
image := NewDockerImage(client)
sub, err := image.ListImages()
assert.NotNil(t, sub)
assert.Nil(t, err)
}
func TestImagePush(t *testing.T) {
createTestImages("test_1")
image.PushImages("test_1")
image.DelImage("test_1")
}
func TestImageDelete(t *testing.T) {
createTestImages("test_123")
dels, err := image.DelImage("test_123")
assert.NotNil(t, dels)
assert.Nil(t, err)
}
func createTestImages(name string) error {
var testDockerFile = `FROM scratch
MAINTAINER Tracy Li
EXPOSE 9090 9091
CMD ["/bin/true"]
`
return image.BuildImage(testDockerFile, "./", "name")
}
func TestImageCreate(t *testing.T) {
err := createTestImages("test_create")
assert.Nil(t, err)
_, err = image.DelImage("test_1")
assert.Nil(t, err)
}
func TestContainerCreate(t *testing.T) {
err := createTestImages("test_c_1")
assert.Nil(t, err)
config := container.Config{}
config.Image = "test_c_1"
id, err := image.CreateContainer("test-container", &config, nil)
if err != nil {
t.Error(err)
t.Fatal(err)
}
err = image.RemoveContainer(id)
if err != nil {
t.Error(err)
t.Fatal(err)
}
_, err = image.DelImage("test_c_1")
assert.Nil(t, err)
log.Debugf("Container id: %s", id)
}