2018-07-03 16:42:03 -05:00
package integration
import (
"net/http"
"os"
"time"
"github.com/gambol99/go-marathon"
"github.com/go-check/check"
2020-09-16 15:46:04 +02:00
"github.com/traefik/traefik/v2/integration/try"
2018-07-03 16:42:03 -05:00
checker "github.com/vdemeester/shakers"
)
2021-11-25 10:10:06 +00:00
// Marathon test suites.
2018-07-03 16:42:03 -05:00
type MarathonSuite15 struct {
BaseSuite
marathonURL string
}
func ( s * MarathonSuite15 ) SetUpSuite ( c * check . C ) {
s . createComposeProject ( c , "marathon15" )
2021-11-25 10:10:06 +00:00
s . composeUp ( c )
2018-07-03 16:42:03 -05:00
2021-11-25 10:10:06 +00:00
s . marathonURL = "http://" + containerNameMarathon + ":8080"
2018-07-03 16:42:03 -05:00
// Wait for Marathon readiness prior to creating the client so that we
// don't run into the "all cluster members down" state right from the
// start.
err := try . GetRequest ( s . marathonURL + "/v2/leader" , 1 * time . Minute , try . StatusCodeIs ( http . StatusOK ) )
c . Assert ( err , checker . IsNil )
}
func ( s * MarathonSuite15 ) TestConfigurationUpdate ( c * check . C ) {
// Start Traefik.
file := s . adaptFile ( c , "fixtures/marathon/simple.toml" , struct {
MarathonURL string
} { s . marathonURL } )
defer os . Remove ( file )
cmd , display := s . traefikCmd ( withConfigFile ( file ) )
defer display ( c )
err := cmd . Start ( )
c . Assert ( err , checker . IsNil )
2020-10-09 09:32:03 +02:00
defer s . killCmd ( cmd )
2018-07-03 16:42:03 -05:00
// Wait for Traefik to turn ready.
err = try . GetRequest ( "http://127.0.0.1:8000/" , 2 * time . Second , try . StatusCodeIs ( http . StatusNotFound ) )
c . Assert ( err , checker . IsNil )
// Prepare Marathon client.
config := marathon . NewDefaultConfig ( )
config . URL = s . marathonURL
client , err := marathon . NewClient ( config )
c . Assert ( err , checker . IsNil )
// Create test application to be deployed.
app := marathon . NewDockerApplication ( ) .
Name ( "/whoami" ) .
CPU ( 0.1 ) .
Memory ( 32 ) .
EmptyNetworks ( ) .
2019-03-14 09:30:04 +01:00
AddLabel ( "traefik.http.Routers.rt.Rule" , "PathPrefix(`/service`)" )
2018-07-03 16:42:03 -05:00
app . Container .
Expose ( 80 ) .
Docker .
2020-09-16 15:46:04 +02:00
Container ( "traefik/whoami" )
2018-07-03 16:42:03 -05:00
* app . Networks = append ( * app . Networks , * marathon . NewBridgePodNetwork ( ) )
// Deploy the test application.
deployApplication ( c , client , app )
// Query application via Traefik.
err = try . GetRequest ( "http://127.0.0.1:8000/service" , 30 * time . Second , try . StatusCodeIs ( http . StatusOK ) )
c . Assert ( err , checker . IsNil )
// Create test application with services to be deployed.
app = marathon . NewDockerApplication ( ) .
Name ( "/whoami" ) .
CPU ( 0.1 ) .
Memory ( 32 ) .
EmptyNetworks ( ) .
2019-03-14 09:30:04 +01:00
AddLabel ( "traefik.http.Routers.app.Rule" , "PathPrefix(`/app`)" )
2018-07-03 16:42:03 -05:00
app . Container .
Expose ( 80 ) .
Docker .
2020-09-16 15:46:04 +02:00
Container ( "traefik/whoami" )
2018-07-03 16:42:03 -05:00
* app . Networks = append ( * app . Networks , * marathon . NewBridgePodNetwork ( ) )
// Deploy the test application.
deployApplication ( c , client , app )
// Query application via Traefik.
err = try . GetRequest ( "http://127.0.0.1:8000/app" , 30 * time . Second , try . StatusCodeIs ( http . StatusOK ) )
c . Assert ( err , checker . IsNil )
}