A small update of libkermit
Using compose/check package (and less code) Signed-off-by: Vincent Demeester <vincent@sbr.pm>
This commit is contained in:
parent
585aeb8f0b
commit
e1448eb238
11 changed files with 78 additions and 72 deletions
|
@ -6,8 +6,9 @@ import (
|
|||
"time"
|
||||
|
||||
"fmt"
|
||||
"github.com/go-check/check"
|
||||
|
||||
checker "github.com/vdemeester/shakers"
|
||||
check "gopkg.in/check.v1"
|
||||
)
|
||||
|
||||
// SimpleSuite
|
||||
|
|
|
@ -6,11 +6,11 @@ import (
|
|||
"os/exec"
|
||||
"time"
|
||||
|
||||
"github.com/go-check/check"
|
||||
"github.com/hashicorp/consul/api"
|
||||
docker "github.com/vdemeester/libkermit/docker"
|
||||
|
||||
docker "github.com/vdemeester/libkermit/docker/check"
|
||||
checker "github.com/vdemeester/shakers"
|
||||
check "gopkg.in/check.v1"
|
||||
)
|
||||
|
||||
// Consul catalog test suites
|
||||
|
@ -22,16 +22,12 @@ type ConsulCatalogSuite struct {
|
|||
}
|
||||
|
||||
func (s *ConsulCatalogSuite) SetUpSuite(c *check.C) {
|
||||
project, err := docker.NewProjectFromEnv()
|
||||
c.Assert(err, checker.IsNil, check.Commentf("Error while creating docker project"))
|
||||
s.project = project
|
||||
s.project = docker.NewProjectFromEnv(c)
|
||||
|
||||
s.createComposeProject(c, "consul_catalog")
|
||||
err = s.composeProject.Start()
|
||||
c.Assert(err, checker.IsNil, check.Commentf("Error starting project"))
|
||||
s.composeProject.Start(c)
|
||||
|
||||
consul, err := s.project.Inspect("integration-test-consul_catalog_consul_1")
|
||||
c.Assert(err, checker.IsNil, check.Commentf("Error finding consul container"))
|
||||
consul := s.project.Inspect(c, "integration-test-consul_catalog_consul_1")
|
||||
|
||||
s.consulIP = consul.NetworkSettings.IPAddress
|
||||
config := api.DefaultConfig()
|
||||
|
@ -98,8 +94,7 @@ func (s *ConsulCatalogSuite) TestSingleService(c *check.C) {
|
|||
c.Assert(err, checker.IsNil)
|
||||
defer cmd.Process.Kill()
|
||||
|
||||
nginx, err := s.project.Inspect("integration-test-consul_catalog_nginx_1")
|
||||
c.Assert(err, checker.IsNil, check.Commentf("Error finding nginx container"))
|
||||
nginx := s.project.Inspect(c, "integration-test-consul_catalog_nginx_1")
|
||||
|
||||
err = s.registerService("test", nginx.NetworkSettings.IPAddress, 80)
|
||||
c.Assert(err, checker.IsNil, check.Commentf("Error registering service"))
|
||||
|
|
|
@ -5,8 +5,9 @@ import (
|
|||
"os/exec"
|
||||
"time"
|
||||
|
||||
"github.com/go-check/check"
|
||||
|
||||
checker "github.com/vdemeester/shakers"
|
||||
check "gopkg.in/check.v1"
|
||||
)
|
||||
|
||||
// Consul test suites (using libcompose)
|
||||
|
|
|
@ -11,10 +11,11 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/docker/docker/pkg/namesgenerator"
|
||||
"github.com/vdemeester/libkermit/docker"
|
||||
"github.com/go-check/check"
|
||||
|
||||
d "github.com/vdemeester/libkermit/docker"
|
||||
docker "github.com/vdemeester/libkermit/docker/check"
|
||||
checker "github.com/vdemeester/shakers"
|
||||
check "gopkg.in/check.v1"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -36,46 +37,42 @@ type DockerSuite struct {
|
|||
}
|
||||
|
||||
func (s *DockerSuite) startContainer(c *check.C, image string, args ...string) string {
|
||||
return s.startContainerWithConfig(c, image, docker.ContainerConfig{
|
||||
return s.startContainerWithConfig(c, image, d.ContainerConfig{
|
||||
Cmd: args,
|
||||
})
|
||||
}
|
||||
|
||||
func (s *DockerSuite) startContainerWithLabels(c *check.C, image string, labels map[string]string, args ...string) string {
|
||||
return s.startContainerWithConfig(c, image, docker.ContainerConfig{
|
||||
return s.startContainerWithConfig(c, image, d.ContainerConfig{
|
||||
Cmd: args,
|
||||
Labels: labels,
|
||||
})
|
||||
}
|
||||
|
||||
func (s *DockerSuite) startContainerWithConfig(c *check.C, image string, config docker.ContainerConfig) string {
|
||||
func (s *DockerSuite) startContainerWithConfig(c *check.C, image string, config d.ContainerConfig) string {
|
||||
if config.Name == "" {
|
||||
config.Name = namesgenerator.GetRandomName(10)
|
||||
}
|
||||
|
||||
container, err := s.project.StartWithConfig(image, config)
|
||||
c.Assert(err, checker.IsNil, check.Commentf("Error starting a container using config %v", config))
|
||||
container := s.project.StartWithConfig(c, image, config)
|
||||
|
||||
// FIXME(vdemeester) this is ugly (it's because of the / in front of the name in docker..)
|
||||
return strings.SplitAfter(container.Name, "/")[1]
|
||||
}
|
||||
|
||||
func (s *DockerSuite) SetUpSuite(c *check.C) {
|
||||
project, err := docker.NewProjectFromEnv()
|
||||
c.Assert(err, checker.IsNil, check.Commentf("Error while creating docker project"))
|
||||
project := docker.NewProjectFromEnv(c)
|
||||
s.project = project
|
||||
|
||||
// Pull required images
|
||||
for repository, tag := range RequiredImages {
|
||||
image := fmt.Sprintf("%s:%s", repository, tag)
|
||||
s.project.Pull(image)
|
||||
c.Assert(err, checker.IsNil, check.Commentf("Error while pulling image %s", image))
|
||||
s.project.Pull(c, image)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TearDownTest(c *check.C) {
|
||||
err := s.project.Clean(os.Getenv("CIRCLECI") != "")
|
||||
c.Assert(err, checker.IsNil, check.Commentf("Error while cleaning containers"))
|
||||
s.project.Clean(c, os.Getenv("CIRCLECI") != "")
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestSimpleConfiguration(c *check.C) {
|
||||
|
|
|
@ -5,8 +5,9 @@ import (
|
|||
"os/exec"
|
||||
"time"
|
||||
|
||||
"github.com/go-check/check"
|
||||
|
||||
checker "github.com/vdemeester/shakers"
|
||||
check "gopkg.in/check.v1"
|
||||
)
|
||||
|
||||
// Etcd test suites (using libcompose)
|
||||
|
|
|
@ -5,8 +5,9 @@ import (
|
|||
"os/exec"
|
||||
"time"
|
||||
|
||||
"github.com/go-check/check"
|
||||
|
||||
checker "github.com/vdemeester/shakers"
|
||||
check "gopkg.in/check.v1"
|
||||
)
|
||||
|
||||
// File test suites
|
||||
|
@ -15,7 +16,7 @@ type FileSuite struct{ BaseSuite }
|
|||
func (s *FileSuite) SetUpSuite(c *check.C) {
|
||||
s.createComposeProject(c, "file")
|
||||
|
||||
s.composeProject.Start()
|
||||
s.composeProject.Start(c)
|
||||
}
|
||||
|
||||
func (s *FileSuite) TestSimpleConfiguration(c *check.C) {
|
||||
|
|
|
@ -8,8 +8,9 @@ import (
|
|||
"os/exec"
|
||||
"time"
|
||||
|
||||
"github.com/go-check/check"
|
||||
|
||||
checker "github.com/vdemeester/shakers"
|
||||
check "gopkg.in/check.v1"
|
||||
)
|
||||
|
||||
// HTTPSSuite
|
||||
|
|
|
@ -11,10 +11,10 @@ import (
|
|||
"text/template"
|
||||
|
||||
"github.com/containous/traefik/integration/utils"
|
||||
"github.com/vdemeester/libkermit/compose"
|
||||
"github.com/go-check/check"
|
||||
|
||||
compose "github.com/vdemeester/libkermit/compose/check"
|
||||
checker "github.com/vdemeester/shakers"
|
||||
check "gopkg.in/check.v1"
|
||||
)
|
||||
|
||||
func Test(t *testing.T) {
|
||||
|
@ -41,17 +41,14 @@ type BaseSuite struct {
|
|||
func (s *BaseSuite) TearDownSuite(c *check.C) {
|
||||
// shutdown and delete compose project
|
||||
if s.composeProject != nil {
|
||||
err := s.composeProject.Stop()
|
||||
c.Assert(err, checker.IsNil)
|
||||
s.composeProject.Stop(c)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *BaseSuite) createComposeProject(c *check.C, name string) {
|
||||
projectName := fmt.Sprintf("integration-test-%s", name)
|
||||
composeFile := fmt.Sprintf("resources/compose/%s.yml", name)
|
||||
composeProject, err := compose.CreateProject(projectName, composeFile)
|
||||
c.Assert(err, checker.IsNil)
|
||||
s.composeProject = composeProject
|
||||
s.composeProject = compose.CreateProject(c, projectName, composeFile)
|
||||
}
|
||||
|
||||
func (s *BaseSuite) traefikCmd(c *check.C, args ...string) (*exec.Cmd, string) {
|
||||
|
|
|
@ -5,8 +5,9 @@ import (
|
|||
"os/exec"
|
||||
"time"
|
||||
|
||||
"github.com/go-check/check"
|
||||
|
||||
checker "github.com/vdemeester/shakers"
|
||||
check "gopkg.in/check.v1"
|
||||
)
|
||||
|
||||
// Marathon test suites (using libcompose)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue