2017-07-06 14:28:13 +00:00
|
|
|
package integration
|
2017-06-30 23:04:18 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"os"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/containous/traefik/integration/try"
|
|
|
|
"github.com/go-check/check"
|
|
|
|
checker "github.com/vdemeester/shakers"
|
|
|
|
)
|
|
|
|
|
|
|
|
// ErrorPagesSuite test suites (using libcompose)
|
2017-07-10 12:58:31 +00:00
|
|
|
type ErrorPagesSuite struct {
|
|
|
|
BaseSuite
|
|
|
|
ErrorPageIP string
|
|
|
|
BackendIP string
|
2017-06-30 23:04:18 +00:00
|
|
|
}
|
|
|
|
|
2017-07-10 12:58:31 +00:00
|
|
|
func (s *ErrorPagesSuite) SetUpSuite(c *check.C) {
|
|
|
|
s.createComposeProject(c, "error_pages")
|
|
|
|
s.composeProject.Start(c)
|
|
|
|
|
|
|
|
s.ErrorPageIP = s.composeProject.Container(c, "nginx2").NetworkSettings.IPAddress
|
|
|
|
s.BackendIP = s.composeProject.Container(c, "nginx1").NetworkSettings.IPAddress
|
|
|
|
}
|
2017-06-30 23:04:18 +00:00
|
|
|
|
2017-07-10 12:58:31 +00:00
|
|
|
func (s *ErrorPagesSuite) TestSimpleConfiguration(c *check.C) {
|
2017-06-30 23:04:18 +00:00
|
|
|
|
2017-07-10 12:58:31 +00:00
|
|
|
file := s.adaptFile(c, "fixtures/error_pages/simple.toml", struct {
|
2017-06-30 23:04:18 +00:00
|
|
|
Server1 string
|
|
|
|
Server2 string
|
2017-07-10 12:58:31 +00:00
|
|
|
}{s.BackendIP, s.ErrorPageIP})
|
2017-06-30 23:04:18 +00:00
|
|
|
defer os.Remove(file)
|
|
|
|
|
2017-07-10 12:58:31 +00:00
|
|
|
cmd, _ := s.cmdTraefik(withConfigFile(file))
|
2017-06-30 23:04:18 +00:00
|
|
|
err := cmd.Start()
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
defer cmd.Process.Kill()
|
|
|
|
|
|
|
|
frontendReq, err := http.NewRequest(http.MethodGet, "http://127.0.0.1:80", nil)
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
frontendReq.Host = "test.local"
|
|
|
|
|
|
|
|
err = try.Request(frontendReq, 2*time.Second, try.BodyContains("nginx"))
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
}
|
|
|
|
|
2017-07-10 12:58:31 +00:00
|
|
|
func (s *ErrorPagesSuite) TestErrorPage(c *check.C) {
|
2017-06-30 23:04:18 +00:00
|
|
|
|
|
|
|
//error.toml contains a mis-configuration of the backend host
|
2017-07-10 12:58:31 +00:00
|
|
|
file := s.adaptFile(c, "fixtures/error_pages/error.toml", struct {
|
2017-06-30 23:04:18 +00:00
|
|
|
Server1 string
|
|
|
|
Server2 string
|
2017-07-10 12:58:31 +00:00
|
|
|
}{s.BackendIP, s.ErrorPageIP})
|
2017-06-30 23:04:18 +00:00
|
|
|
defer os.Remove(file)
|
|
|
|
|
2017-07-10 12:58:31 +00:00
|
|
|
cmd, _ := s.cmdTraefik(withConfigFile(file))
|
2017-06-30 23:04:18 +00:00
|
|
|
err := cmd.Start()
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
defer cmd.Process.Kill()
|
|
|
|
|
|
|
|
frontendReq, err := http.NewRequest(http.MethodGet, "http://127.0.0.1:80", nil)
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
frontendReq.Host = "test.local"
|
|
|
|
|
|
|
|
err = try.Request(frontendReq, 2*time.Second, try.BodyContains("An error occurred."))
|
|
|
|
c.Assert(err, checker.IsNil)
|
|
|
|
}
|