diff options
-rw-r--r-- | boruta.go | 13 | ||||
-rw-r--r-- | http/client/client.go | 15 | ||||
-rw-r--r-- | http/filter.go | 3 | ||||
-rw-r--r-- | http/filter_test.go | 7 | ||||
-rw-r--r-- | requests/requests_test.go | 21 |
5 files changed, 34 insertions, 25 deletions
@@ -27,6 +27,7 @@ package boruta import ( "crypto/rsa" "net" + "strconv" "time" ) @@ -78,9 +79,21 @@ func (caps Capabilities) GetWorkerUUID() WorkerUUID { // 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 diff --git a/http/client/client.go b/http/client/client.go index 20c79eb..581dc4f 100644 --- a/http/client/client.go +++ b/http/client/client.go @@ -31,7 +31,6 @@ import ( "io/ioutil" "net/http" "reflect" - "strconv" "time" "git.tizen.org/tools/boruta" @@ -195,7 +194,7 @@ func (client *BorutaClient) NewRequest(caps boruta.Capabilities, // 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 @@ -221,7 +220,7 @@ func (client *BorutaClient) UpdateRequest(reqInfo *boruta.ReqInfo) error { 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 @@ -232,7 +231,7 @@ func (client *BorutaClient) UpdateRequest(reqInfo *boruta.ReqInfo) error { // 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 @@ -263,7 +262,7 @@ func (client *BorutaClient) ListRequests(filter boruta.ListFilter) ([]boruta.Req // 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 @@ -291,7 +290,7 @@ func (client *BorutaClient) AcquireWorker(reqID boruta.ReqID) (boruta.AccessInfo // 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 @@ -380,7 +379,7 @@ func (client *BorutaClient) Deregister(uuid boruta.WorkerUUID) error { // 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 @@ -402,7 +401,7 @@ func (client *BorutaClient) GetWorkerState(uuid boruta.WorkerUUID) (boruta.Worke // 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 diff --git a/http/filter.go b/http/filter.go index 895dc39..bca0b4d 100644 --- a/http/filter.go +++ b/http/filter.go @@ -19,7 +19,6 @@ package http import ( - "strconv" "strings" . "git.tizen.org/tools/boruta" @@ -62,7 +61,7 @@ func (filter *RequestFilter) Match(req *ReqInfo) bool { return false } - priority := strconv.FormatUint(uint64(req.Priority), 10) + priority := req.Priority.String() if filter.Priority != "" && priority != filter.Priority { return false } diff --git a/http/filter_test.go b/http/filter_test.go index f367943..c9f6c20 100644 --- a/http/filter_test.go +++ b/http/filter_test.go @@ -19,7 +19,6 @@ package http import ( - "strconv" "testing" . "git.tizen.org/tools/boruta" @@ -29,7 +28,7 @@ import ( 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, @@ -68,11 +67,11 @@ func TestMatch(t *testing.T) { 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, }, { diff --git a/requests/requests_test.go b/requests/requests_test.go index 3dcb708..993d2c2 100644 --- a/requests/requests_test.go +++ b/requests/requests_test.go @@ -19,7 +19,6 @@ package requests import ( "errors" "net" - "strconv" "testing" "time" @@ -332,7 +331,7 @@ func (filter *reqFilter) Match(req *ReqInfo) bool { return false } - priority := strconv.FormatUint(uint64(req.Priority), 10) + priority := req.Priority.String() if filter.priority != "" && priority != filter.priority { return false } @@ -374,42 +373,42 @@ func TestListRequests(t *testing.T) { { 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}, }, @@ -437,21 +436,21 @@ func TestListRequests(t *testing.T) { { 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, }, |