Exemplo n.º 1
0
func DoRequest(r *sling.Sling) *http.Response {
	req, err := r.Request()
	Expect(err).To(BeNil())
	response, err := http.DefaultClient.Do(req)

	Expect(err).To(BeNil())
	return response
}
Exemplo n.º 2
0
// newStreamService returns a new StreamService.
func newStreamService(client *http.Client, sling *sling.Sling) *StreamService {
	sling.Set("User-Agent", userAgent)
	return &StreamService{
		client: client,
		public: sling.New().Base(publicStream).Path("statuses/"),
		user:   sling.New().Base(userStream),
		site:   sling.New().Base(siteStream),
	}
}
Exemplo n.º 3
0
func DoRequestThroughProxy(r *sling.Sling) *http.Response {
	req, err := r.Request()
	Expect(err).To(BeNil())

	proxy, err := url.Parse(hoverflyProxyUrl)
	proxyHttpClient := &http.Client{Transport: &http.Transport{Proxy: http.ProxyURL(proxy)}, CheckRedirect: func(req *http.Request, via []*http.Request) error { return http.ErrUseLastResponse }}
	response, err := proxyHttpClient.Do(req)

	Expect(err).To(BeNil())

	return response
}
Exemplo n.º 4
0
func DoRequestThroughProxy(r *sling.Sling) *http.Response {
	req, err := r.Request()
	Expect(err).To(BeNil())

	proxy, err := url.Parse(hoverflyProxyUrl)
	proxyHttpClient := &http.Client{Transport: &http.Transport{Proxy: http.ProxyURL(proxy)}}
	response, err := proxyHttpClient.Do(req)

	Expect(err).To(BeNil())

	return response
}
Exemplo n.º 5
0
func request(_sling *sling.Sling, acceptHeader string, authInfo ...usrInfo) (int, []byte, error) {
	_sling = _sling.Set("Accept", acceptHeader)
	req, err := _sling.Request()
	if err != nil {
		return 400, nil, err
	}
	if len(authInfo) > 0 {
		req.SetBasicAuth(authInfo[0].Name, authInfo[0].Passwd)
	}
	w := httptest.NewRecorder()
	beego.BeeApp.Handlers.ServeHTTP(w, req)
	body, err := ioutil.ReadAll(w.Body)
	return w.Code, body, err
}
Exemplo n.º 6
0
func (h *Hoverfly) doRequest(request *sling.Sling) (*http.Response, error) {
	httpRequest, err := request.Request()
	if err != nil {
		log.Debug(err.Error())
		return nil, errors.New("Could not communicate with Hoverfly")
	}

	response, err := h.httpClient.Do(httpRequest)
	if err != nil {
		log.Debug(err.Error())
		return nil, errors.New("Could not communicate with Hoverfly")
	}

	if response.StatusCode == 401 {
		return nil, errors.New("Hoverfly requires authentication")
	}

	return response, nil
}
Exemplo n.º 7
0
func (h *Hoverfly) performAPIRequest(slingRequest *sling.Sling) (*http.Response, error) {
	slingRequest, err := h.addAuthIfNeeded(slingRequest)
	if err != nil {
		log.Warn(err.Error())
		return nil, errors.New("Could not authenticate  with Hoverfly")
	}

	request, err := slingRequest.Request()

	if err != nil {
		log.Warn(err.Error())
		return nil, errors.New("Could not communicate with Hoverfly")
	}

	response, err := h.httpClient.Do(request)
	if err != nil {
		log.Warn(err.Error())
		return nil, errors.New("Could not communicate with Hoverfly")
	}
	return response, nil

}
Exemplo n.º 8
0
func (h *Hoverfly) addAuthIfNeeded(sling *sling.Sling) (*sling.Sling, error) {
	if len(h.Username) > 0 || len(h.Password) > 0 && len(h.authToken) == 0 {
		var err error

		h.authToken, err = h.generateAuthToken()
		if err != nil {
			return nil, err
		}
	}

	if len(h.authToken) > 0 {
		sling.Add("Authorization", h.buildAuthorizationHeaderValue())
	}

	return sling, nil
}
Exemplo n.º 9
0
func newSchemaService(sling *sling.Sling) *SchemaService {
	return &SchemaService{
		sling: sling.Path("schemas"),
	}
}
Exemplo n.º 10
0
// newUserService returns a new UserService.
func newUserService(sling *sling.Sling) *UserService {
	return &UserService{
		sling: sling.Path("users/"),
	}
}
Exemplo n.º 11
0
func newGroupService(sling *sling.Sling) *GroupService {
	return &GroupService{
		sling: sling.Path("group/"),
	}
}
Exemplo n.º 12
0
func newStoreService(sling *sling.Sling) *StoreService {
	return &StoreService{
		sling: sling.Path("store"),
	}
}
Exemplo n.º 13
0
	"net/http"
	"os/exec"

	"github.com/dghubble/sling"
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"github.com/onsi/gomega/gexec"
	"github.com/rosenhouse/cnsim/models"
	"github.com/sclevine/agouti"
	. "github.com/sclevine/agouti/matchers"
)

var _ = Describe("CNSim Server", func() {
	var (
		session *gexec.Session
		address string

		apiClient *sling.Sling
	)

	var serverIsAvailable = func() error {
		return VerifyTCPConnection(address)
	}

	BeforeEach(func() {
		port := 10000 + rand.Intn(10000)
		serverCmd := exec.Command(pathToServer)
		serverCmd.Env = []string{fmt.Sprintf("PORT=%d", port)}
		var err error
		session, err = gexec.Start(serverCmd, GinkgoWriter, GinkgoWriter)
		Expect(err).NotTo(HaveOccurred())
Exemplo n.º 14
0
// newAccountService returns a new AccountService.
func newAccountService(sling *sling.Sling) *AccountService {
	return &AccountService{
		sling: sling.Path("account/"),
	}
}
Exemplo n.º 15
0
// newStatusService returns a new StatusService.
func newStatusService(sling *sling.Sling) *StatusService {
	return &StatusService{
		sling: sling.Path("statuses/"),
	}
}
Exemplo n.º 16
0
// newTimelineService returns a new TimelineService.
func newTimelineService(sling *sling.Sling) *TimelineService {
	return &TimelineService{
		sling: sling.Path("statuses/"),
	}
}
Exemplo n.º 17
0
// newDirectMessageService returns a new StatusService.
func newDirectMessageService(sling *sling.Sling) *DirectMessageService {
	return &DirectMessageService{
		baseSling: sling.New(),
		sling:     sling.Path("direct_messages/"),
	}
}
Exemplo n.º 18
0
// NewUserService return a new UserService
func NewUserService(sling *sling.Sling) *UserService {
	return &UserService{
		sling: sling.Path(""),
	}
}
Exemplo n.º 19
0
func newAuthService(sling *sling.Sling) *AuthService {
	return &AuthService{
		sling: sling.Path("auth/"),
	}
}
Exemplo n.º 20
0
// newFollowerService returns a new FollowerService.
func newFollowerService(sling *sling.Sling) *FollowerService {
	return &FollowerService{
		sling: sling.Path("followers/"),
	}
}
Exemplo n.º 21
0
// NewObjectService returns a new ObjectService
func NewObjectService(sling *sling.Sling) *ObjectService {
	return &ObjectService{
		sling: sling.Path("classes/"),
	}
}