2015-09-27 15:59:51 +02:00
// This is the main file that sets up integration tests using go-check.
2017-07-06 16:28:13 +02:00
package integration
2015-09-27 15:59:51 +02:00
import (
2017-05-17 15:22:44 +02:00
"bytes"
2015-09-27 15:59:51 +02:00
"fmt"
2015-09-28 22:37:19 +02:00
"io/ioutil"
2016-12-12 18:30:31 +01:00
"net"
2015-09-28 22:37:19 +02:00
"os"
"os/exec"
"path/filepath"
2015-09-27 15:59:51 +02:00
"testing"
2015-09-28 22:37:19 +02:00
"text/template"
2015-09-27 15:59:51 +02:00
2016-02-24 16:43:39 +01:00
"github.com/containous/traefik/integration/utils"
2016-04-02 12:40:21 +02:00
"github.com/go-check/check"
2016-07-21 16:19:51 +02:00
compose "github.com/libkermit/compose/check"
2015-09-27 15:59:51 +02:00
checker "github.com/vdemeester/shakers"
)
func Test ( t * testing . T ) {
check . TestingT ( t )
}
func init ( ) {
check . Suite ( & SimpleSuite { } )
2016-04-20 11:54:57 -07:00
check . Suite ( & AccessLogSuite { } )
2015-11-21 02:59:49 +01:00
check . Suite ( & HTTPSSuite { } )
2015-09-27 15:59:51 +02:00
check . Suite ( & FileSuite { } )
2017-04-26 01:08:32 +02:00
check . Suite ( & HealthCheckSuite { } )
2015-09-27 15:59:51 +02:00
check . Suite ( & DockerSuite { } )
check . Suite ( & ConsulSuite { } )
2016-02-02 18:03:40 +01:00
check . Suite ( & ConsulCatalogSuite { } )
2016-02-25 23:31:35 +00:00
check . Suite ( & EtcdSuite { } )
2015-09-27 15:59:51 +02:00
check . Suite ( & MarathonSuite { } )
2016-05-20 17:17:38 +02:00
check . Suite ( & ConstraintSuite { } )
2016-07-20 11:56:14 +02:00
check . Suite ( & MesosSuite { } )
2016-11-16 23:21:47 +01:00
check . Suite ( & EurekaSuite { } )
2016-12-12 18:30:31 +01:00
check . Suite ( & AcmeSuite { } )
2017-03-08 18:53:34 -07:00
check . Suite ( & DynamoDBSuite { } )
2017-06-30 16:04:18 -07:00
check . Suite ( & ErrorPagesSuite { } )
2015-09-27 15:59:51 +02:00
}
var traefikBinary = "../dist/traefik"
type BaseSuite struct {
2016-03-27 19:58:08 +02:00
composeProject * compose . Project
2015-09-27 15:59:51 +02:00
}
func ( s * BaseSuite ) TearDownSuite ( c * check . C ) {
// shutdown and delete compose project
if s . composeProject != nil {
2016-04-02 12:40:21 +02:00
s . composeProject . Stop ( c )
2015-09-27 15:59:51 +02:00
}
}
func ( s * BaseSuite ) createComposeProject ( c * check . C , name string ) {
2016-03-27 19:58:08 +02:00
projectName := fmt . Sprintf ( "integration-test-%s" , name )
composeFile := fmt . Sprintf ( "resources/compose/%s.yml" , name )
2016-12-12 18:30:31 +01:00
addrs , err := net . InterfaceAddrs ( )
c . Assert ( err , checker . IsNil )
for _ , addr := range addrs {
ip , _ , err := net . ParseCIDR ( addr . String ( ) )
c . Assert ( err , checker . IsNil )
if ! ip . IsLoopback ( ) && ip . To4 ( ) != nil {
os . Setenv ( "DOCKER_HOST_IP" , ip . String ( ) )
break
}
}
2016-04-02 12:40:21 +02:00
s . composeProject = compose . CreateProject ( c , projectName , composeFile )
2015-09-27 15:59:51 +02:00
}
2015-09-28 22:37:19 +02:00
2017-05-17 15:22:44 +02:00
// Deprecated: unused
2015-09-28 22:37:19 +02:00
func ( s * BaseSuite ) traefikCmd ( c * check . C , args ... string ) ( * exec . Cmd , string ) {
cmd , out , err := utils . RunCommand ( traefikBinary , args ... )
c . Assert ( err , checker . IsNil , check . Commentf ( "Fail to run %s with %v" , traefikBinary , args ) )
return cmd , out
}
2017-05-17 15:22:44 +02:00
func ( s * BaseSuite ) cmdTraefikWithConfigFile ( file string ) ( * exec . Cmd , * bytes . Buffer ) {
return s . cmdTraefik ( "--configFile=" + file )
}
func ( s * BaseSuite ) cmdTraefik ( args ... string ) ( * exec . Cmd , * bytes . Buffer ) {
cmd := exec . Command ( traefikBinary , args ... )
var out bytes . Buffer
cmd . Stdout = & out
cmd . Stderr = & out
return cmd , & out
}
func ( s * BaseSuite ) displayTraefikLog ( c * check . C , output * bytes . Buffer ) {
if output == nil || output . Len ( ) == 0 {
fmt . Printf ( "%s: No Traefik logs present." , c . TestName ( ) )
} else {
fmt . Printf ( "%s: Traefik logs: " , c . TestName ( ) )
fmt . Println ( output . String ( ) )
}
}
2015-09-28 22:37:19 +02:00
func ( s * BaseSuite ) adaptFileForHost ( c * check . C , path string ) string {
dockerHost := os . Getenv ( "DOCKER_HOST" )
if dockerHost == "" {
// Default docker socket
dockerHost = "unix:///var/run/docker.sock"
}
2016-04-28 01:43:43 +02:00
tempObjects := struct { DockerHost string } { dockerHost }
return s . adaptFile ( c , path , tempObjects )
}
2015-09-28 22:37:19 +02:00
2016-04-28 01:43:43 +02:00
func ( s * BaseSuite ) adaptFile ( c * check . C , path string , tempObjects interface { } ) string {
2015-09-28 22:37:19 +02:00
// Load file
tmpl , err := template . ParseFiles ( path )
c . Assert ( err , checker . IsNil )
folder , prefix := filepath . Split ( path )
tmpFile , err := ioutil . TempFile ( folder , prefix )
c . Assert ( err , checker . IsNil )
defer tmpFile . Close ( )
2016-04-28 01:43:43 +02:00
err = tmpl . ExecuteTemplate ( tmpFile , prefix , tempObjects )
2015-09-28 22:37:19 +02:00
c . Assert ( err , checker . IsNil )
err = tmpFile . Sync ( )
c . Assert ( err , checker . IsNil )
return tmpFile . Name ( )
}