import (
"crypto/rsa"
"net"
+ "strconv"
"time"
)
// ReqID refers to the Request created by the User.
type ReqID uint64
+// String returns string representation of ReqID. This is implementation of
+// fmt.Stringer interface.
+func (id ReqID) String() string {
+ return strconv.FormatUint(uint64(id), 10)
+}
+
// Priority is the importance of the Request. Lower - more important.
type Priority uint8
+// String returns string representation of Priority. This is implementation of
+// fmt.Stringer interface.
+func (p Priority) String() string {
+ return strconv.FormatUint(uint64(p), 10)
+}
+
const (
// HiPrio - most important priority (minimum value).
HiPrio Priority = 1
"io/ioutil"
"net/http"
"reflect"
- "strconv"
"time"
"git.tizen.org/tools/boruta"
// CloseRequest closes or cancels Boruta request.
func (client *BorutaClient) CloseRequest(reqID boruta.ReqID) error {
- path := client.url + "reqs/" + strconv.Itoa(int(reqID)) + "/close"
+ path := client.url + "reqs/" + reqID.String() + "/close"
resp, err := http.Post(path, "", nil)
if err != nil {
return err
if err != nil {
return err
}
- path := client.url + "reqs/" + strconv.Itoa(int(reqInfo.ID))
+ path := client.url + "reqs/" + reqInfo.ID.String()
resp, err := http.Post(path, contentType, bytes.NewReader(req))
if err != nil {
return err
// GetRequestInfo queries Boruta server for details about given request ID.
func (client *BorutaClient) GetRequestInfo(reqID boruta.ReqID) (boruta.ReqInfo, error) {
var reqInfo boruta.ReqInfo
- path := client.url + "reqs/" + strconv.Itoa(int(reqID))
+ path := client.url + "reqs/" + reqID.String()
resp, err := http.Get(path)
if err != nil {
return reqInfo, err
// is issued because requests need to have assigned worker.
func (client *BorutaClient) AcquireWorker(reqID boruta.ReqID) (boruta.AccessInfo, error) {
var accInfo boruta.AccessInfo
- path := client.url + "reqs/" + strconv.Itoa(int(reqID)) + "/acquire_worker"
+ path := client.url + "reqs/" + reqID.String() + "/acquire_worker"
resp, err := http.Post(path, "", nil)
if err != nil {
return accInfo, err
// If not called, Boruta server will terminate the tunnel when ReqInfo.Job.Timeout
// passes, and change state of request to CLOSED.
func (client *BorutaClient) ProlongAccess(reqID boruta.ReqID) error {
- path := client.url + "reqs/" + strconv.Itoa(int(reqID)) + "/prolong"
+ path := client.url + "reqs/" + reqID.String() + "/prolong"
resp, err := http.Post(path, "", nil)
if err != nil {
return err
// should always check for an error before proceeding with actions dependent on
// request state.
func (client *BorutaClient) GetRequestState(reqID boruta.ReqID) (boruta.ReqState, error) {
- path := client.url + "reqs/" + strconv.Itoa(int(reqID))
+ path := client.url + "reqs/" + reqID.String()
headers, err := getHeaders(path)
if err != nil {
return boruta.FAILED, err
// reqID will timeout. The request must be in INPROGRESS state.
func (client *BorutaClient) GetJobTimeout(reqID boruta.ReqID) (time.Time, error) {
var t time.Time
- path := client.url + "reqs/" + strconv.Itoa(int(reqID))
+ path := client.url + "reqs/" + reqID.String()
headers, err := getHeaders(path)
if err != nil {
return t, err
package http
import (
- "strconv"
"strings"
. "git.tizen.org/tools/boruta"
return false
}
- priority := strconv.FormatUint(uint64(req.Priority), 10)
+ priority := req.Priority.String()
if filter.Priority != "" && priority != filter.Priority {
return false
}
package http
import (
- "strconv"
"testing"
. "git.tizen.org/tools/boruta"
func TestNewRequestFilter(t *testing.T) {
assert := assert.New(t)
state := string(WAIT)
- priority := strconv.FormatUint(uint64(HiPrio), 10)
+ priority := HiPrio.String()
filter := &RequestFilter{
State: state,
Priority: priority,
result bool
}{
{
- priority: strconv.FormatUint(uint64(req.Priority), 10),
+ priority: req.Priority.String(),
result: true,
},
{
- priority: strconv.FormatUint(uint64(req.Priority+1), 10),
+ priority: (req.Priority + 1).String(),
result: false,
},
{
import (
"errors"
"net"
- "strconv"
"testing"
"time"
return false
}
- priority := strconv.FormatUint(uint64(req.Priority), 10)
+ priority := req.Priority.String()
if filter.priority != "" && priority != filter.priority {
return false
}
{
filter: reqFilter{
state: string(WAIT),
- priority: strconv.FormatUint(uint64(req.Priority), 10),
+ priority: req.Priority.String(),
},
result: map[ReqID]bool{ReqID(1): true},
},
{
filter: reqFilter{
state: string(WAIT),
- priority: strconv.FormatUint(uint64(req.Priority+1), 10),
+ priority: (req.Priority + 1).String(),
},
result: map[ReqID]bool{ReqID(2): true},
},
{
filter: reqFilter{
state: string(DONE),
- priority: strconv.FormatUint(uint64(req.Priority), 10),
+ priority: req.Priority.String(),
},
result: map[ReqID]bool{ReqID(3): true},
},
{
filter: reqFilter{
state: string(DONE),
- priority: strconv.FormatUint(uint64(req.Priority+1), 10),
+ priority: (req.Priority + 1).String(),
},
result: map[ReqID]bool{ReqID(4): true},
},
{
filter: reqFilter{
state: "",
- priority: strconv.FormatUint(uint64(req.Priority), 10),
+ priority: req.Priority.String(),
},
result: map[ReqID]bool{ReqID(1): true, ReqID(3): true},
},
{
filter: reqFilter{
state: "",
- priority: strconv.FormatUint(uint64(req.Priority+1), 10),
+ priority: (req.Priority + 1).String(),
},
result: map[ReqID]bool{ReqID(2): true, ReqID(4): true},
},
{
filter: reqFilter{
state: string(notFoundState),
- priority: strconv.FormatUint(uint64(notFoundPrio), 10),
+ priority: notFoundPrio.String(),
},
result: noReqs,
},
{
filter: reqFilter{
state: string(WAIT),
- priority: strconv.FormatUint(uint64(notFoundPrio), 10),
+ priority: notFoundPrio.String(),
},
result: noReqs,
},
{
filter: reqFilter{
state: string(notFoundState),
- priority: strconv.FormatUint(uint64(req.Priority), 10),
+ priority: req.Priority.String(),
},
result: noReqs,
},