Пример #1
0
func (suite *errorsImplSuite) SetupTest() {
	suite.Suite.SetupTest()
	suite.rawErrs = map[string]errors.Error{
		"uid1": errors.InternalServerError("com.foo.uid1", "uid1"),
		"uid2": errors.InternalServerError("com.foo.uid2", "uid2"),
		"uid3": errors.InternalServerError("com.foo.uid2", "uid3"), // Same service uid as uid2
	}
	suite.errs = &errorsImpl{}
	for uid, err := range suite.rawErrs {
		req, reqErr := client.NewJsonRequest(err.Code(), err.Description(), nil)
		if reqErr != nil {
			panic(reqErr)
		}
		suite.errs.set(uid, req, err, nil)
	}
}
func TestJsonHttpCall(t *testing.T) {
	// zoning service is OpenToTheWorld and should have _some_ zone surrounding Somerset House
	json := []byte(`{"location":{"lat":51.510761,"lng":-0.1174437}}`)
	req, err := client.NewJsonRequest("com.hailocab.service.zoning", "search", json)
	if err != nil {
		t.Fatalf("Error creating request: %v", err)
	}
	rsp := &searchproto.Response{}

	caller := HttpCaller("https://api2-staging.elasticride.com")
	perr := caller(req, rsp)

	if perr != nil {
		t.Fatalf("Error executing request: %v", perr)
	}

	if len(rsp.GetZones()) == 0 {
		t.Error("Expecting > 0 zones, got back 0")
	}
}
func TestJsonHttpCallThatFails(t *testing.T) {
	// discovery service is NOT open to the world, because it's a kernel service
	req, err := client.NewJsonRequest("com.hailocab.kernel.discovery", "services", []byte(`{}`))
	if err != nil {
		t.Fatalf("Error creating request: %v", err)
	}
	rsp := &servicesproto.Response{}

	caller := HttpCaller("https://api2-staging.elasticride.com")
	perr := caller(req, rsp)

	if perr == nil {
		t.Fatal("We are EXPECTING as error executing request")
	}

	if perr.Code() != "com.hailocab.api.rpc.auth" {
		t.Errorf("Expecting code 'com.hailocab.api.rpc.auth' got '%s'", perr.Code())
	}
	if perr.Type() != "FORBIDDEN" {
		t.Errorf("Expecting type 'FORBIDDEN' got '%s'", perr.Type())
	}
}
Пример #4
0
// ScopedJsonRequest does just the same as ScopedRequest but with JSON payload
func (self *Request) ScopedJsonRequest(service, endpoint string, payload []byte) (*client.Request, error) {
	r, err := client.NewJsonRequest(service, endpoint, payload)
	if err != nil {
		return nil, err
	}
	// load in scope
	if self.SessionID() != "" {
		r.SetSessionID(self.SessionID())
	} else {
		// double check Auth() scope
		if self.Auth().IsAuth() {
			r.SetSessionID(self.Auth().AuthUser().SessId)
		}
	}
	r.SetTraceID(self.TraceID())
	r.SetParentMessageID(self.MessageID())

	// scope -- who WE are (not who sent it to us)
	r.SetFrom(Name)
	r.SetFromEndpoint(self.Endpoint())

	return r, nil
}