Skip to content

Commit

Permalink
Extend Marathon integration test.
Browse files Browse the repository at this point in the history
  • Loading branch information
timoreimann committed Apr 10, 2017
1 parent 726edb3 commit 4dabfe1
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 15 deletions.
10 changes: 10 additions & 0 deletions integration/fixtures/marathon/with-entrypoint.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
defaultEntryPoints = ["http"]

[entryPoints]
[entryPoints.http]
address = ":8000"

logLevel = "DEBUG"

[marathon]
entrypoint = "http://127.0.0.1:8080"
59 changes: 44 additions & 15 deletions integration/marathon_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package main

import (
"fmt"
"net/http"
"os/exec"
"time"

"github.com/containous/traefik/integration/utils"
marathon "github.com/gambol99/go-marathon"
"github.com/go-check/check"

checker "github.com/vdemeester/shakers"
Expand All @@ -14,20 +17,9 @@ import (
type MarathonSuite struct{ BaseSuite }

func (s *MarathonSuite) SetUpSuite(c *check.C) {
fmt.Println("setting up marathon compose file")
s.createComposeProject(c, "marathon")
s.composeProject.Start(c)
// wait for marathon
// err := utils.TryRequest("http://127.0.0.1:8080/ping", 60*time.Second, func(res *http.Response) error {
// body, err := ioutil.ReadAll(res.Body)
// if err != nil {
// return err
// }
// if !strings.Contains(string(body), "ping") {
// return errors.New("Incorrect marathon config")
// }
// return nil
// })
// c.Assert(err, checker.IsNil)
}

func (s *MarathonSuite) TestSimpleConfiguration(c *check.C) {
Expand All @@ -36,11 +28,48 @@ func (s *MarathonSuite) TestSimpleConfiguration(c *check.C) {
c.Assert(err, checker.IsNil)
defer cmd.Process.Kill()

time.Sleep(500 * time.Millisecond)
var resp *http.Response
// TODO validate : run on 80
resp, err := http.Get("http://127.0.0.1:8000/")
err = utils.TryRequest("http://127.0.0.1:8000/", 5*time.Second, func(res *http.Response) error {
resp = res
return nil
})
c.Assert(err, checker.IsNil)
defer resp.Body.Close()

// Expected a 404 as we did not configure anything
c.Assert(err, checker.IsNil)
c.Assert(resp.StatusCode, checker.Equals, 404)
}

func (s *MarathonSuite) TestConfigurationUpdate(c *check.C) {
cmd := exec.Command(traefikBinary, "--configFile=fixtures/marathon/with-entrypoint.toml")
err := cmd.Start()
c.Assert(err, checker.IsNil)
defer cmd.Process.Kill()

marathonURL := "http://marathon:8080"
fmt.Printf("polling Marathon URL %s for availability\n", marathonURL)
// wait for marathon
err = utils.TryRequest(fmt.Sprintf("%s/ping", marathonURL), 360*time.Second, func(res *http.Response) error {
res.Body.Close()
return nil
})
c.Assert(err, checker.IsNil)

// Prepare Marathon client.
config := marathon.NewDefaultConfig()
config.URL = marathonURL
client, err := marathon.NewClient(config)
c.Assert(err, checker.IsNil)

// Deploy test application via Marathon.
app := marathon.NewDockerApplication().Name("/whoami").CPU(0.1).Memory(32)
app.Container.Docker.Container("emilevauge/whoami")

fmt.Println("deploying test application")
deployID, err := client.UpdateApplication(app, false)
c.Assert(err, checker.IsNil)
c.Assert(client.WaitOnDeployment(deployID.DeploymentID, 30*time.Second), checker.IsNil)

fmt.Println("done.")
}

0 comments on commit 4dabfe1

Please sign in to comment.