From 9da373dc3f2dda756c9fafa91359503aa0517947 Mon Sep 17 00:00:00 2001 From: Emmanuel Quentin Date: Tue, 15 Apr 2014 08:37:36 +0200 Subject: [PATCH] Fix tests --- container/container.go | 4 +--- container/container_test.go | 3 +-- gaudi/gaudi_unit_test.go | 11 +++-------- tests/gaudi_functional_test.go | 4 ++-- 4 files changed, 7 insertions(+), 15 deletions(-) diff --git a/container/container.go b/container/container.go index 414e9af..b5e1f9e 100644 --- a/container/container.go +++ b/container/container.go @@ -157,8 +157,6 @@ 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()+")") @@ -166,7 +164,7 @@ func (c *Container) Start(rebuild bool) { } cleanChan := make(chan bool, 1) - c.Clean(cleanChan) + go c.Clean(cleanChan) <-cleanChan } diff --git a/container/container_test.go b/container/container_test.go index 16989da..efcecd8 100644 --- a/container/container_test.go +++ b/container/container_test.go @@ -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") diff --git a/gaudi/gaudi_unit_test.go b/gaudi/gaudi_unit_test.go index bd2eba0..83ab5af 100644 --- a/gaudi/gaudi_unit_test.go +++ b/gaudi/gaudi_unit_test.go @@ -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(` @@ -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) } @@ -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), ) @@ -155,7 +150,7 @@ applications: type: mysql `) - g.StartApplications() + g.StartApplications(true) c.Assert(len(g.Applications), Equals, 5) } diff --git a/tests/gaudi_functional_test.go b/tests/gaudi_functional_test.go index f7d7093..dfb0d5b 100644 --- a/tests/gaudi_functional_test.go +++ b/tests/gaudi_functional_test.go @@ -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) @@ -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