Skip to content

Commit 7ee5d36

Browse files
smothikimboersma
authored andcommitted
test(utils) : add basic functional test files
1 parent 4adcc65 commit 7ee5d36

126 files changed

Lines changed: 17697 additions & 10 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

registry/Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ FROM deis/base:latest
22
MAINTAINER Gabriel Monroy <gabriel@opdemand.com>
33

44
# install required packages (copied from dotcloud/docker-registry Dockerfile)
5-
RUN sed -i 's/main$/main universe/' /etc/apt/sources.list && apt-get update
5+
RUN sed -i 's/main$/main universe/' /etc/apt/sources.list
6+
RUN apt-get update
67
RUN apt-get install -y git-core build-essential python-dev \
78
libevent-dev python-openssl liblzma-dev wget
89

registry/Makefile

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,16 @@ full-clean: clean
2929

3030
test: test-unit test-functional
3131

32-
test-unit: .PHONY
33-
@if [ ! -d test-unit ]; then \
34-
git clone -b 0.6.8 https://github.com/dotcloud/docker-registry test-unit; \
32+
test-unit:
33+
@if [ ! -d test-unit.tmp ]; then \
34+
git clone -b 0.6.8 https://github.com/dotcloud/docker-registry test-unit.tmp; \
3535
fi
3636
@if [ ! -d venv ]; then virtualenv venv; fi
37-
venv/bin/pip install -q -r test-unit/requirements.txt
38-
venv/bin/pip install -q -r test-unit/test-requirements.txt
39-
cd test-unit && \
37+
venv/bin/pip install -q -r test-unit.tmp/requirements.txt
38+
venv/bin/pip install -q -r test-unit.tmp/test-requirements.txt
39+
cd test-unit.tmp && \
4040
DOCKER_REGISTRY_CONFIG=config_test.yml SETTINGS_FLAVOR=test PYTHONPATH=test \
4141
../venv/bin/python -m unittest discover -s test
4242

4343
test-functional:
44-
@echo no functional tests
45-
46-
.PHONY:
44+
GOPATH=$(CURDIR)/../test/_vendor:$(GOPATH) go test -v ./test/...

registry/test/run_test.go

Lines changed: 271 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,271 @@
1+
package verbose
2+
3+
import (
4+
"github.com/dotcloud/docker/api/client"
5+
"bufio"
6+
"fmt"
7+
"io"
8+
"time"
9+
"testing"
10+
"strings"
11+
12+
)
13+
14+
15+
16+
const (
17+
unitTestImageName = "docker-test-image"
18+
unitTestImageID = "83599e29c455eb719f77d799bc7c51521b9551972f5a850d7ad265bc1b5292f6" // 1.0
19+
unitTestImageIDShort = "83599e29c455"
20+
unitTestNetworkBridge = "testdockbr0"
21+
unitTestStoreBase = "/var/lib/docker/unit-tests"
22+
testDaemonAddr = "172.17.8.100:4243"
23+
testDaemonProto = "tcp"
24+
testDaemonHttpsProto = "tcp"
25+
testDaemonHttpsAddr = "localhost:4271"
26+
testDaemonRogueHttpsAddr = "localhost:4272"
27+
)
28+
29+
func closeWrap(args ...io.Closer) error {
30+
e := false
31+
ret := fmt.Errorf("Error closing elements")
32+
for _, c := range args {
33+
if err := c.Close(); err != nil {
34+
e = true
35+
ret = fmt.Errorf("%s\n%s", ret, err)
36+
}
37+
}
38+
if e {
39+
return ret
40+
}
41+
return nil
42+
}
43+
44+
45+
func getIPAdressTest(t *testing.T) string{
46+
stdin, _ := io.Pipe()
47+
stdout, stdoutPipe := io.Pipe()
48+
cli := client.NewDockerCli(nil, stdoutPipe, nil, testDaemonProto, testDaemonAddr, nil)
49+
var IPAdress string
50+
go func(){
51+
err:= cli.CmdInspect("--format","{{ .NetworkSettings.IPAddress }}","deis-etcd")
52+
if err != nil {
53+
t.Fatalf("getIPAdressTest %s",err)
54+
}
55+
if err = closeWrap(stdout, stdoutPipe,stdin); err != nil {
56+
t.Fatalf("getIPAdressTest %s",err)
57+
}
58+
}()
59+
time.Sleep(2000 * time.Millisecond)
60+
for{
61+
if cmdBytes,err:= bufio.NewReader(stdout).ReadString('\n'); err==nil{
62+
IPAdress=cmdBytes
63+
fmt.Println(cmdBytes)
64+
}else{
65+
break
66+
}
67+
fmt.Println("get IPAddress")
68+
}
69+
return IPAdress
70+
}
71+
72+
73+
74+
75+
func pullEtcdTest(t *testing.T,done chan bool){
76+
stdin, _ := io.Pipe()
77+
stdout, stdoutPipe := io.Pipe()
78+
fmt.Println("1")
79+
cli := client.NewDockerCli(nil, stdoutPipe, nil, testDaemonProto, testDaemonAddr, nil)
80+
fmt.Println("2")
81+
go func (){
82+
err:= cli.CmdPull("phife.atribecalledchris.com:5000/deis/etcd:0.3.0")
83+
if err != nil {
84+
t.Fatalf("pullEtcdTest %s",err)
85+
}
86+
if err = closeWrap(stdout, stdoutPipe,stdin); err != nil {
87+
t.Fatalf("pullEtcdTest %s",err)
88+
}
89+
}( )
90+
time.Sleep(3000 * time.Millisecond)
91+
for{
92+
if cmdBytes,err:= bufio.NewReader(stdout).ReadString('\n'); err==nil{
93+
fmt.Println(cmdBytes)
94+
}else{
95+
break
96+
}
97+
fmt.Println("pulling etcd")
98+
}
99+
done<-true
100+
101+
}
102+
103+
func runEtcdTest(t *testing.T,done chan bool){
104+
stdin, _ := io.Pipe()
105+
stdout, stdoutPipe := io.Pipe()
106+
cli := client.NewDockerCli(nil, stdoutPipe, nil, testDaemonProto, testDaemonAddr, nil)
107+
go func (){
108+
fmt.Println("12")
109+
err:= cli.CmdRun("--name","deis-etcd","phife.atribecalledchris.com:5000/deis/etcd:0.3.0")
110+
if err != nil {
111+
t.Fatalf("runEtcdTest %s",err)
112+
}
113+
114+
}( )
115+
go func() {
116+
fmt.Println("here")
117+
time.Sleep(5000 * time.Millisecond)
118+
if err := closeWrap(stdout, stdoutPipe,stdin); err != nil {
119+
t.Fatalf("runEtcdTest %s",err)
120+
}
121+
}()
122+
time.Sleep(1000 * time.Millisecond)
123+
for{
124+
if cmdBytes,err:= bufio.NewReader(stdout).ReadString('\n'); err==nil{
125+
fmt.Println(cmdBytes)
126+
}else{
127+
break
128+
}
129+
fmt.Println("Running Etcd ")
130+
}
131+
done<-true
132+
}
133+
134+
func buildRegistryTest(t *testing.T){
135+
stdin, _ := io.Pipe()
136+
stdout, stdoutPipe := io.Pipe()
137+
cli := client.NewDockerCli(nil, stdoutPipe, nil, testDaemonProto, testDaemonAddr, nil)
138+
go func ( ){
139+
err:= cli.CmdBuild("../")
140+
if err != nil {
141+
t.Fatalf("buildRegistryTest %s",err)
142+
}
143+
if err = closeWrap(stdout, stdoutPipe,stdin); err != nil {
144+
t.Fatalf("buildRegistryTest %s",err)
145+
}
146+
}( )
147+
time.Sleep(3000 * time.Millisecond)
148+
for{
149+
if cmdBytes,err:= bufio.NewReader(stdout).ReadString('\n'); err==nil{
150+
fmt.Println(cmdBytes)
151+
}else{
152+
break
153+
}
154+
fmt.Println("building Deis registy Dockerfile")
155+
}
156+
}
157+
158+
func runDeisRegistryDataTest(t *testing.T){
159+
stdin, _ := io.Pipe()
160+
stdout, stdoutPipe := io.Pipe()
161+
162+
cli := client.NewDockerCli(nil, stdoutPipe, nil, testDaemonProto, testDaemonAddr, nil)
163+
164+
go func ( ){
165+
err:= cli.CmdInspect("--format","'{{ .Config.Hostname }}'","deis-registry-data")
166+
/*if err != nil {
167+
t.Fatalf("runDeisRegistryDataTest %s",err)
168+
}*/
169+
if err = closeWrap(stdout, stdoutPipe,stdin); err != nil {
170+
t.Fatalf("runDeisRegistryDataTest %s",err)
171+
}
172+
}( )
173+
go func() {
174+
//fmt.Println("here1")
175+
time.Sleep(2000 * time.Millisecond)
176+
if err := closeWrap(stdout, stdoutPipe,stdin); err != nil {
177+
t.Fatalf("runEtcdTest %s",err)
178+
}
179+
}()
180+
var hostname string
181+
time.Sleep(1000 * time.Millisecond)
182+
for{
183+
if cmdBytes,err:= bufio.NewReader(stdout).ReadString('\n'); err==nil{
184+
fmt.Println(cmdBytes)
185+
hostname=cmdBytes
186+
}else{
187+
break
188+
}
189+
fmt.Println("inspecting deis registry data")
190+
}
191+
192+
if strings.Contains(hostname, "Error") ==true {
193+
go func ( ){
194+
err:= cli.CmdRun("--name","deis-registry-data","-v","/data","deis/base","/bin/true")
195+
if err != nil {
196+
t.Fatalf("%s",err)
197+
}
198+
if err := closeWrap(stdout, stdoutPipe,stdin); err != nil {
199+
t.Fatalf("%s",err)
200+
}
201+
}( )
202+
for{
203+
if cmdBytes,err:= bufio.NewReader(stdout).ReadString('\n'); err==nil{
204+
fmt.Println(cmdBytes)
205+
}else{
206+
break
207+
}
208+
fmt.Println("pulling Deis registry data")
209+
}
210+
}
211+
}
212+
213+
214+
func runDeisRegistryTest(t *testing.T,IPAddress string){
215+
stdin, _ := io.Pipe()
216+
stdout, stdoutPipe := io.Pipe()
217+
cli := client.NewDockerCli(nil, stdoutPipe, nil, testDaemonProto, testDaemonAddr, nil)
218+
go func (){
219+
//docker run --name deis-registry -p 5000:5000 -e PUBLISH=5000 -e HOST=10.0.0.37 --volumes-from deis-registry-data deis/registry
220+
221+
err:= cli.CmdRun("--name","deis-registry","-p","5000:5000","-e","PUBLISH=5000","-e","HOST="+IPAddress,"--volumes-from","deis-registry-data","deis/registry")
222+
if err != nil {
223+
t.Fatalf("runDeisRegistryTest %s",err)
224+
}
225+
if err := closeWrap(stdout, stdoutPipe,stdin); err != nil {
226+
t.Fatalf("runDeisRegistryTest %s",err)
227+
}
228+
}( )
229+
time.Sleep(3000 * time.Millisecond)
230+
for{
231+
if cmdBytes,err:= bufio.NewReader(stdout).ReadString('\n'); err==nil{
232+
if strings.Contains(cmdBytes, "Booting") ==true {
233+
if err := closeWrap(stdout, stdoutPipe,stdin); err != nil {
234+
t.Fatalf("runDeisRegistryTest %s",err)
235+
}
236+
}
237+
fmt.Println(cmdBytes)
238+
}else{
239+
break
240+
}
241+
fmt.Println("pulling Deis Registry")
242+
}
243+
244+
}
245+
246+
247+
248+
249+
func TestBuild(t *testing.T) {
250+
done := make(chan bool, 1)
251+
done2 := make(chan bool,1)
252+
pullEtcdTest(t,done)
253+
fmt.Println("1st")
254+
go func() {
255+
fmt.Println("2nd")
256+
<-done
257+
fmt.Println("3rd")
258+
runEtcdTest(t,done2)
259+
fmt.Println("4th")
260+
}()
261+
<-done2
262+
fmt.Println("5th")
263+
buildRegistryTest(t)
264+
fmt.Println("6th")
265+
runDeisRegistryDataTest(t)
266+
fmt.Println("7th")
267+
IPAddress:=strings.TrimSuffix(getIPAdressTest(t), "\n")
268+
fmt.Println(IPAddress)
269+
fmt.Println("8th")
270+
runDeisRegistryTest(t,IPAddress)
271+
}

0 commit comments

Comments
 (0)