2017-07-06 17:28:13 +03:00
package integration
2015-09-27 16:59:51 +03:00
import (
"net/http"
2024-01-09 19:00:07 +03:00
"testing"
2015-09-27 16:59:51 +03:00
"time"
2018-07-03 11:02:03 +03:00
"github.com/gambol99/go-marathon"
2024-01-09 19:00:07 +03:00
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
2020-09-16 16:46:04 +03:00
"github.com/traefik/traefik/v2/integration/try"
2015-09-27 16:59:51 +03:00
)
2021-11-25 13:10:06 +03:00
const containerNameMarathon = "marathon"
2017-04-10 10:28:00 +03:00
2021-11-25 13:10:06 +03:00
// Marathon test suites.
2017-04-10 10:28:00 +03:00
type MarathonSuite struct {
BaseSuite
marathonURL string
}
2016-03-27 17:27:56 +03:00
2024-01-09 19:00:07 +03:00
func TestMarathonSuite ( t * testing . T ) {
suite . Run ( t , new ( MarathonSuite ) )
}
func ( s * MarathonSuite ) SetUpSuite ( ) {
s . BaseSuite . SetupSuite ( )
s . createComposeProject ( "marathon" )
s . composeUp ( )
2017-05-17 16:22:44 +03:00
2024-01-09 19:00:07 +03:00
s . marathonURL = "http://" + s . getComposeServiceIP ( containerNameMarathon ) + ":8080"
2017-04-10 10:28:00 +03: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 ) )
2024-01-09 19:00:07 +03:00
require . NoError ( s . T ( ) , err )
}
func ( s * MarathonSuite ) TearDownSuite ( ) {
s . BaseSuite . TearDownSuite ( )
2017-04-10 10:28:00 +03:00
}
2024-01-09 19:00:07 +03:00
func ( s * BaseSuite ) deployApplication ( client marathon . Marathon , application * marathon . Application ) {
2017-08-21 11:46:03 +03:00
deploy , err := client . UpdateApplication ( application , false )
2024-01-09 19:00:07 +03:00
require . NoError ( s . T ( ) , err )
2017-08-21 11:46:03 +03:00
// Wait for deployment to complete.
2024-01-09 19:00:07 +03:00
err = client . WaitOnDeployment ( deploy . DeploymentID , 1 * time . Minute )
require . NoError ( s . T ( ) , err )
2017-08-21 11:46:03 +03:00
}
2024-01-09 19:00:07 +03:00
func ( s * MarathonSuite ) TestConfigurationUpdate ( ) {
s . T ( ) . Skip ( "doesn't work" )
2023-05-15 17:38:05 +03:00
2017-04-10 10:28:00 +03:00
// Start Traefik.
2024-01-09 19:00:07 +03:00
file := s . adaptFile ( "fixtures/marathon/simple.toml" , struct {
2017-04-10 10:28:00 +03:00
MarathonURL string
} { s . marathonURL } )
2022-07-13 19:32:08 +03:00
2024-01-09 19:00:07 +03:00
s . traefikCmd ( withConfigFile ( file ) )
2015-09-27 16:59:51 +03:00
2017-04-10 10:28:00 +03:00
// Wait for Traefik to turn ready.
2024-01-09 19:00:07 +03:00
err := try . GetRequest ( "http://127.0.0.1:8000/" , 2 * time . Second , try . StatusCodeIs ( http . StatusNotFound ) )
require . NoError ( s . T ( ) , err )
2017-04-10 10:28:00 +03:00
// Prepare Marathon client.
config := marathon . NewDefaultConfig ( )
config . URL = s . marathonURL
client , err := marathon . NewClient ( config )
2024-01-09 19:00:07 +03:00
require . NoError ( s . T ( ) , err )
2017-04-10 10:28:00 +03:00
// Create test application to be deployed.
app := marathon . NewDockerApplication ( ) .
Name ( "/whoami" ) .
CPU ( 0.1 ) .
Memory ( 32 ) .
2019-03-14 11:30:04 +03:00
AddLabel ( "traefik.http.Routers.rt.Rule" , "PathPrefix(`/service`)" )
2017-04-10 10:28:00 +03:00
app . Container . Docker . Bridged ( ) .
Expose ( 80 ) .
2020-09-16 16:46:04 +03:00
Container ( "traefik/whoami" )
2017-04-10 10:28:00 +03:00
// Deploy the test application.
2024-01-09 19:00:07 +03:00
s . deployApplication ( client , app )
2017-05-17 16:22:44 +03:00
2017-04-10 10:28:00 +03:00
// Query application via Traefik.
err = try . GetRequest ( "http://127.0.0.1:8000/service" , 30 * time . Second , try . StatusCodeIs ( http . StatusOK ) )
2024-01-09 19:00:07 +03:00
require . NoError ( s . T ( ) , err )
2017-08-21 11:46:03 +03:00
// Create test application with services to be deployed.
app = marathon . NewDockerApplication ( ) .
Name ( "/whoami" ) .
CPU ( 0.1 ) .
Memory ( 32 ) .
2019-03-14 11:30:04 +03:00
AddLabel ( "traefik.http.Routers.app.Rule" , "PathPrefix(`/app`)" )
2017-08-21 11:46:03 +03:00
app . Container . Docker . Bridged ( ) .
Expose ( 80 ) .
2020-09-16 16:46:04 +03:00
Container ( "traefik/whoami" )
2017-08-21 11:46:03 +03:00
// Deploy the test application.
2024-01-09 19:00:07 +03:00
s . deployApplication ( client , app )
2017-08-21 11:46:03 +03:00
// Query application via Traefik.
err = try . GetRequest ( "http://127.0.0.1:8000/app" , 30 * time . Second , try . StatusCodeIs ( http . StatusOK ) )
2024-01-09 19:00:07 +03:00
require . NoError ( s . T ( ) , err )
2015-09-27 16:59:51 +03:00
}