Skip to content
This repository has been archived by the owner on May 4, 2019. It is now read-only.

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
manuquentin committed Apr 15, 2014
1 parent 8ba4750 commit 9da373d
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 15 deletions.
4 changes: 1 addition & 3 deletions container/container.go
Expand Up @@ -157,16 +157,14 @@ func (c *Container) Start(rebuild bool) {
c.init()

// Check if the container is already running
c.RetrieveIp()

if !rebuild {
if c.IsRunning() {
fmt.Println("Application", c.Name, "is already running", "("+c.Ip+":"+c.GetFirstPort()+")")
return
}

cleanChan := make(chan bool, 1)
c.Clean(cleanChan)
go c.Clean(cleanChan)
<-cleanChan
}

Expand Down
3 changes: 1 addition & 2 deletions container/container_test.go
Expand Up @@ -24,12 +24,11 @@ func (s *ContainerTestSuite) TestStartedApplicationShouldRetrieveItsIp(c *C) {
// Setup the docker mock package
docker.MOCK().SetController(ctrl)
docker.EXPECT().Start(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return("123")
docker.EXPECT().Inspect(gomock.Any()).Return([]byte("[{\"ID\": \"123\", \"State\":{\"Running\": false}, \"NetworkSettings\": {\"IPAddress\": \"\"}}]"), nil)
docker.EXPECT().Inspect(gomock.Any()).Return([]byte("[{\"ID\": \"123\", \"State\":{\"Running\": true}, \"NetworkSettings\": {\"IPAddress\": \"172.17.0.10\"}}]"), nil)

// @TODO : find a way to mock time.Sleep
container := container.Container{Name: "Test"}
container.Start()
container.Start(true)

c.Check(container.IsRunning(), Equals, true)
c.Check(container.Ip, Equals, "172.17.0.10")
Expand Down
11 changes: 3 additions & 8 deletions gaudi/gaudi_unit_test.go
Expand Up @@ -75,7 +75,7 @@ func (s *GaudiTestSuite) TestStartApplicationShouldCleanAndBuildThem(c *C) {
docker.EXPECT().Remove(gomock.Any()).Return().Times(2)
docker.EXPECT().Build(gomock.Any(), gomock.Any()).Return().Times(2)
docker.EXPECT().Start(gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return("123").Times(2)
docker.EXPECT().Inspect(gomock.Any()).Return([]byte("[{\"ID\": \"123\", \"State\":{\"Running\": false}, \"NetworkSettings\": {\"IPAddress\": \"172.17.0.10\"}}]"), nil).Times(4)
docker.EXPECT().Inspect(gomock.Any()).Return([]byte("[{\"ID\": \"123\", \"State\":{\"Running\": false}, \"NetworkSettings\": {\"IPAddress\": \"172.17.0.10\"}}]"), nil).Times(2)

g := gaudi.Gaudi{}
g.Init(`
Expand All @@ -91,7 +91,7 @@ applications:

c.Assert(len(g.Applications), Equals, 2)

g.StartApplications()
g.StartApplications(true)
c.Assert(g.GetApplication("db").IsRunning(), Equals, true)
c.Assert(g.GetApplication("app").IsRunning(), Equals, true)
}
Expand All @@ -110,24 +110,19 @@ func (s *GaudiTestSuite) TestStartApplicationShouldStartThemByOrderOfDependencie
docker.EXPECT().Build(gomock.Any(), gomock.Any()).Return().Times(5)

gomock.InOrder(
docker.EXPECT().Inspect("db").Return([]byte("[{\"ID\": \"100\", \"State\":{\"Running\": false}, \"NetworkSettings\": {\"IPAddress\": \"172.17.0.10\"}}]"), nil),
docker.EXPECT().Start("db", gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return("100"),
docker.EXPECT().Inspect("100").Return([]byte("[{\"ID\": \"100\", \"State\":{\"Running\": true}, \"NetworkSettings\": {\"IPAddress\": \"172.17.0.10\"}}]"), nil),

docker.EXPECT().Inspect("app").Return([]byte("[{\"ID\": \"101\", \"State\":{\"Running\": false}, \"NetworkSettings\": {\"IPAddress\": \"172.17.0.10\"}}]"), nil),
docker.EXPECT().Start("app", gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return("101"),
docker.EXPECT().Inspect("101").Return([]byte("[{\"ID\": \"101\", \"State\":{\"Running\": true}, \"NetworkSettings\": {\"IPAddress\": \"172.17.0.10\"}}]"), nil),

docker.EXPECT().Inspect("front1").Return([]byte("[{\"ID\": \"102\", \"State\":{\"Running\": false}, \"NetworkSettings\": {\"IPAddress\": \"172.17.0.10\"}}]"), nil),
docker.EXPECT().Start("front1", gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return("102"),

docker.EXPECT().Inspect("front2").Return([]byte("[{\"ID\": \"103\", \"State\":{\"Running\": false}, \"NetworkSettings\": {\"IPAddress\": \"172.17.0.10\"}}]"), nil),
docker.EXPECT().Start("front2", gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return("103"),

docker.EXPECT().Inspect("102").Return([]byte("[{\"ID\": \"102\", \"State\":{\"Running\": true}, \"NetworkSettings\": {\"IPAddress\": \"172.17.0.10\"}}]"), nil),
docker.EXPECT().Inspect("103").Return([]byte("[{\"ID\": \"103\", \"State\":{\"Running\": true}, \"NetworkSettings\": {\"IPAddress\": \"172.17.0.10\"}}]"), nil),

docker.EXPECT().Inspect("lb").Return([]byte("[{\"ID\": \"104\", \"State\":{\"Running\": false}, \"NetworkSettings\": {\"IPAddress\": \"172.17.0.10\"}}]"), nil),
docker.EXPECT().Start("lb", gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any(), gomock.Any()).Return("104"),
docker.EXPECT().Inspect("104").Return([]byte("[{\"ID\": \"104\", \"State\":{\"Running\": true}, \"NetworkSettings\": {\"IPAddress\": \"172.17.0.10\"}}]"), nil),
)
Expand Down Expand Up @@ -155,7 +150,7 @@ applications:
type: mysql
`)

g.StartApplications()
g.StartApplications(true)
c.Assert(len(g.Applications), Equals, 5)
}

Expand Down
4 changes: 2 additions & 2 deletions tests/gaudi_functional_test.go
Expand Up @@ -29,7 +29,7 @@ applications:
`)

c.Assert(len(g.Applications), Equals, 1)
g.StartApplications()
g.StartApplications(true)

// Test apache is running
resp, err := http.Get("http://" + g.GetApplication("front").Ip)
Expand Down Expand Up @@ -66,7 +66,7 @@ applications:
`)

c.Assert(len(g.Applications), Equals, 2)
g.StartApplications()
g.StartApplications(true)
time.Sleep(2 * time.Second)

// Test apache is running
Expand Down

0 comments on commit 9da373d

Please sign in to comment.