~juju-qa/ubuntu/trusty/juju/juju-1.25.8

« back to all changes in this revision

Viewing changes to src/gopkg.in/goose.v1/testing/httpsuite/httpsuite.go

  • Committer: Nicholas Skaggs
  • Date: 2016-12-02 18:01:10 UTC
  • Revision ID: nicholas.skaggs@canonical.com-20161202180110-dl1helep8qfebmhx
ImportĀ upstreamĀ 1.25.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package httpsuite
 
2
 
 
3
// This package provides an HTTPSuite infrastructure that lets you bring up an
 
4
// HTTP server. The server will handle requests based on whatever Handlers are
 
5
// attached to HTTPSuite.Mux. This Mux is reset after every test case, and the
 
6
// server is shut down at the end of the test suite.
 
7
 
 
8
import (
 
9
        "net/http"
 
10
        "net/http/httptest"
 
11
 
 
12
        gc "gopkg.in/check.v1"
 
13
)
 
14
 
 
15
var _ = gc.Suite(&HTTPSuite{})
 
16
 
 
17
type HTTPSuite struct {
 
18
        Server     *httptest.Server
 
19
        Mux        *http.ServeMux
 
20
        oldHandler http.Handler
 
21
        UseTLS     bool
 
22
}
 
23
 
 
24
func (s *HTTPSuite) SetUpSuite(c *gc.C) {
 
25
        // fmt.Printf("Starting New Server\n")
 
26
        if s.UseTLS {
 
27
                s.Server = httptest.NewTLSServer(nil)
 
28
        } else {
 
29
                s.Server = httptest.NewServer(nil)
 
30
        }
 
31
}
 
32
 
 
33
func (s *HTTPSuite) SetUpTest(c *gc.C) {
 
34
        s.oldHandler = s.Server.Config.Handler
 
35
        s.Mux = http.NewServeMux()
 
36
        s.Server.Config.Handler = s.Mux
 
37
}
 
38
 
 
39
func (s *HTTPSuite) TearDownTest(c *gc.C) {
 
40
        s.Mux = nil
 
41
        s.Server.Config.Handler = s.oldHandler
 
42
}
 
43
 
 
44
func (s *HTTPSuite) TearDownSuite(c *gc.C) {
 
45
        if s.Server != nil {
 
46
                // fmt.Printf("Stopping Server\n")
 
47
                s.Server.Close()
 
48
        }
 
49
}