-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhttp_test.go
68 lines (51 loc) · 1.71 KB
/
http_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Copyright 2014 Canonical Ltd.
// Licensed under the AGPLv3, see LICENCE file for details.
package api_test
import (
"net/http"
jc "github.com/juju/testing/checkers"
gc "gopkg.in/check.v1"
"github.com/juju/juju/api"
apihttp "github.com/juju/juju/api/http"
apihttptesting "github.com/juju/juju/api/http/testing"
jujutesting "github.com/juju/juju/juju/testing"
)
type httpSuite struct {
apihttptesting.HTTPSuite
jujutesting.JujuConnSuite
}
var _ = gc.Suite(&httpSuite{})
func (s *httpSuite) SetUpTest(c *gc.C) {
s.HTTPSuite.SetUpTest(c)
s.JujuConnSuite.SetUpTest(c)
// This determines the client used in SendHTTPRequest().
s.PatchValue(api.NewHTTPClient,
func(*api.State) apihttp.HTTPClient {
return s.Fake
},
)
}
func (s *httpSuite) TestNewHTTPRequestSuccess(c *gc.C) {
req, err := s.APIState.NewHTTPRequest("GET", "somefacade")
c.Assert(err, jc.ErrorIsNil)
s.CheckRequest(c, req, "GET", "somefacade")
}
func (s *httpSuite) TestNewHTTPClientCorrectTransport(c *gc.C) {
httpClient := s.APIState.NewHTTPClient()
c.Assert(httpClient.Transport, gc.NotNil)
c.Assert(httpClient.Transport, gc.FitsTypeOf, (*http.Transport)(nil))
config := httpClient.Transport.(*http.Transport).TLSClientConfig
c.Check(config.RootCAs, gc.NotNil)
}
func (s *httpSuite) TestNewHTTPClientValidatesCert(c *gc.C) {
req, err := s.APIState.NewHTTPRequest("GET", "somefacade")
httpClient := s.APIState.NewHTTPClient()
resp, err := httpClient.Do(req)
c.Assert(err, jc.ErrorIsNil)
c.Check(resp.StatusCode, gc.Equals, http.StatusNotFound)
}
func (s *httpSuite) TestSendHTTPRequestSuccess(c *gc.C) {
req, resp, err := s.APIState.SendHTTPRequest("somefacade", nil)
c.Assert(err, jc.ErrorIsNil)
s.Fake.CheckCalled(c, req, resp)
}