Minor refactor as requested in PR comments
This commit is contained in:
parent
8bac454792
commit
bf1f6f663a
4 changed files with 27 additions and 37 deletions
0
examples/k8s.namespace.sh
Normal file → Executable file
0
examples/k8s.namespace.sh
Normal file → Executable file
|
@ -37,9 +37,9 @@ func (s *AccessLogSuite) TestAccessLog(c *check.C) {
|
||||||
time.Sleep(500 * time.Millisecond)
|
time.Sleep(500 * time.Millisecond)
|
||||||
|
|
||||||
// Verify Traefik started OK
|
// Verify Traefik started OK
|
||||||
if traefikLog, err := ioutil.ReadFile("traefik.log"); err != nil {
|
traefikLog, err := ioutil.ReadFile("traefik.log")
|
||||||
c.Assert(err.Error(), checker.Equals, "")
|
c.Assert(err, checker.IsNil)
|
||||||
} else if len(traefikLog) > 0 {
|
if len(traefikLog) > 0 {
|
||||||
fmt.Printf("%s\n", string(traefikLog))
|
fmt.Printf("%s\n", string(traefikLog))
|
||||||
c.Assert(len(traefikLog), checker.Equals, 0)
|
c.Assert(len(traefikLog), checker.Equals, 0)
|
||||||
}
|
}
|
||||||
|
@ -61,17 +61,15 @@ func (s *AccessLogSuite) TestAccessLog(c *check.C) {
|
||||||
c.Assert(err, checker.IsNil)
|
c.Assert(err, checker.IsNil)
|
||||||
|
|
||||||
// Verify access.log output as expected
|
// Verify access.log output as expected
|
||||||
if accessLog, err := ioutil.ReadFile("access.log"); err != nil {
|
accessLog, err := ioutil.ReadFile("access.log")
|
||||||
c.Assert(err.Error(), checker.Equals, "")
|
c.Assert(err, checker.IsNil)
|
||||||
} else {
|
|
||||||
lines := strings.Split(string(accessLog), "\n")
|
lines := strings.Split(string(accessLog), "\n")
|
||||||
count := 0
|
count := 0
|
||||||
for i, line := range lines {
|
for i, line := range lines {
|
||||||
if len(line) > 0 {
|
if len(line) > 0 {
|
||||||
count++
|
count++
|
||||||
if tokens, err := shellwords.Parse(line); err != nil {
|
tokens, err := shellwords.Parse(line)
|
||||||
c.Assert(err.Error(), checker.Equals, "")
|
c.Assert(err, checker.IsNil)
|
||||||
} else {
|
|
||||||
c.Assert(len(tokens), checker.Equals, 13)
|
c.Assert(len(tokens), checker.Equals, 13)
|
||||||
c.Assert(tokens[6], checker.Equals, "200")
|
c.Assert(tokens[6], checker.Equals, "200")
|
||||||
c.Assert(tokens[9], checker.Equals, fmt.Sprintf("%d", i+1))
|
c.Assert(tokens[9], checker.Equals, fmt.Sprintf("%d", i+1))
|
||||||
|
@ -80,14 +78,12 @@ func (s *AccessLogSuite) TestAccessLog(c *check.C) {
|
||||||
c.Assert(regexp.MustCompile("^\\d+\\.\\d+.*s$").MatchString(tokens[12]), checker.True)
|
c.Assert(regexp.MustCompile("^\\d+\\.\\d+.*s$").MatchString(tokens[12]), checker.True)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
c.Assert(count, checker.Equals, 3)
|
c.Assert(count, checker.Equals, 3)
|
||||||
}
|
|
||||||
|
|
||||||
// Verify no other Traefik problems
|
// Verify no other Traefik problems
|
||||||
if traefikLog, err := ioutil.ReadFile("traefik.log"); err != nil {
|
traefikLog, err = ioutil.ReadFile("traefik.log")
|
||||||
c.Assert(err.Error(), checker.Equals, "")
|
c.Assert(err, checker.IsNil)
|
||||||
} else if len(traefikLog) > 0 {
|
if len(traefikLog) > 0 {
|
||||||
fmt.Printf("%s\n", string(traefikLog))
|
fmt.Printf("%s\n", string(traefikLog))
|
||||||
c.Assert(len(traefikLog), checker.Equals, 0)
|
c.Assert(len(traefikLog), checker.Equals, 0)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,5 @@
|
||||||
package middlewares
|
package middlewares
|
||||||
|
|
||||||
/*
|
|
||||||
Middleware Logger writes each request and its response to the access log.
|
|
||||||
It gets some information from the logInfoResponseWriter set up by previous middleware.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
log "github.com/Sirupsen/logrus"
|
log "github.com/Sirupsen/logrus"
|
||||||
|
@ -23,7 +18,10 @@ const (
|
||||||
loggerReqidHeader = "X-Traefik-Reqid"
|
loggerReqidHeader = "X-Traefik-Reqid"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Logger holds the File defining the access log
|
/*
|
||||||
|
Middleware Logger writes each request and its response to the access log.
|
||||||
|
It gets some information from the logInfoResponseWriter set up by previous middleware.
|
||||||
|
*/
|
||||||
type Logger struct {
|
type Logger struct {
|
||||||
file *os.File
|
file *os.File
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,10 @@
|
||||||
package middlewares
|
package middlewares
|
||||||
|
|
||||||
/*
|
|
||||||
Middleware saveBackend sends the backend name to the logger.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
// SaveBackend holds the next handler
|
// Middleware saveBackend sends the backend name to the logger.
|
||||||
type SaveBackend struct {
|
type SaveBackend struct {
|
||||||
next http.Handler
|
next http.Handler
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue