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"
2024-01-09 19:00:07 +03:00
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
2023-02-03 17:24:05 +03:00
"github.com/traefik/traefik/v3/integration/try"
2015-09-27 16:59:51 +03:00
)
2020-05-11 13:06:07 +03:00
// File tests suite.
2016-03-27 17:27:56 +03:00
type FileSuite struct { BaseSuite }
2024-01-09 19:00:07 +03:00
func TestFileSuite ( t * testing . T ) {
suite . Run ( t , new ( FileSuite ) )
2016-03-27 17:27:56 +03:00
}
2024-01-09 19:00:07 +03:00
func ( s * FileSuite ) SetupSuite ( ) {
s . BaseSuite . SetupSuite ( )
s . createComposeProject ( "file" )
s . composeUp ( )
}
func ( s * FileSuite ) TearDownSuite ( ) {
s . BaseSuite . TearDownSuite ( )
}
func ( s * FileSuite ) TestSimpleConfiguration ( ) {
file := s . adaptFile ( "fixtures/file/simple.toml" , struct { } { } )
s . traefikCmd ( withConfigFile ( file ) )
2015-09-27 16:59:51 +03:00
2015-10-17 15:46:31 +03:00
// Expected a 404 as we did not configure anything
2024-01-09 19:00:07 +03:00
err := try . GetRequest ( "http://127.0.0.1:8000/" , 1000 * time . Millisecond , try . StatusCodeIs ( http . StatusNotFound ) )
require . NoError ( s . T ( ) , err )
2015-10-17 15:46:31 +03:00
}
2020-05-11 13:06:07 +03:00
// #56 regression test, make sure it does not fail?
2024-01-09 19:00:07 +03:00
func ( s * FileSuite ) TestSimpleConfigurationNoPanic ( ) {
s . traefikCmd ( withConfigFile ( "fixtures/file/56-simple-panic.toml" ) )
2015-10-17 15:46:31 +03:00
2015-10-06 22:00:53 +03:00
// Expected a 404 as we did not configure anything
2024-01-09 19:00:07 +03:00
err := try . GetRequest ( "http://127.0.0.1:8000/" , 1000 * time . Millisecond , try . StatusCodeIs ( http . StatusNotFound ) )
require . NoError ( s . T ( ) , err )
2017-05-26 16:32:03 +03:00
}
2024-01-09 19:00:07 +03:00
func ( s * FileSuite ) TestDirectoryConfiguration ( ) {
s . traefikCmd ( withConfigFile ( "fixtures/file/directory.toml" ) )
2017-05-26 16:32:03 +03:00
// Expected a 404 as we did not configure anything at /test
2024-01-09 19:00:07 +03:00
err := try . GetRequest ( "http://127.0.0.1:8000/test" , 1000 * time . Millisecond , try . StatusCodeIs ( http . StatusNotFound ) )
require . NoError ( s . T ( ) , err )
2017-05-26 16:32:03 +03:00
// Expected a 502 as there is no backend server
err = try . GetRequest ( "http://127.0.0.1:8000/test2" , 1000 * time . Millisecond , try . StatusCodeIs ( http . StatusBadGateway ) )
2024-01-09 19:00:07 +03:00
require . NoError ( s . T ( ) , err )
2015-09-27 16:59:51 +03:00
}