summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaciej Wereski <m.wereski@partner.samsung.com>2018-06-21 14:40:02 +0200
committerMaciej Wereski <m.wereski@partner.samsung.com>2018-07-10 10:01:25 +0200
commitc1cf72cddc5a22a222cb44330ade3c83713f7c20 (patch)
tree14bd5a35d27ee33024bfd4689d52c44f5a2bcba9
parent8e63fdf662befa716daca070a650e1859fbf5b82 (diff)
downloadboruta-c1cf72cddc5a22a222cb44330ade3c83713f7c20.tar.gz
boruta-c1cf72cddc5a22a222cb44330ade3c83713f7c20.tar.bz2
boruta-c1cf72cddc5a22a222cb44330ade3c83713f7c20.zip
HTTP API Client: Get worker information
Change-Id: Ie0ef143db2e88cf96cef4267c3257223efb0df63 Signed-off-by: Maciej Wereski <m.wereski@partner.samsung.com>
-rw-r--r--http/client/client.go12
-rw-r--r--http/client/client_test.go47
2 files changed, 52 insertions, 7 deletions
diff --git a/http/client/client.go b/http/client/client.go
index cbc901e..e2c887f 100644
--- a/http/client/client.go
+++ b/http/client/client.go
@@ -301,9 +301,15 @@ func (client *BorutaClient) ListWorkers(groups boruta.Groups,
// GetWorkerInfo queries Boruta server for information about worker with given
// UUID.
-func (client *BorutaClient) GetWorkerInfo(uuid boruta.WorkerUUID) (
- boruta.WorkerInfo, error) {
- return boruta.WorkerInfo{}, util.ErrNotImplemented
+func (client *BorutaClient) GetWorkerInfo(uuid boruta.WorkerUUID) (boruta.WorkerInfo, error) {
+ var info boruta.WorkerInfo
+ path := client.url + "workers/" + string(uuid)
+ resp, err := http.Get(path)
+ if err != nil {
+ return info, err
+ }
+ err = processResponse(resp, &info)
+ return info, err
}
// SetState requests Boruta server to change state of worker with provided UUID.
diff --git a/http/client/client_test.go b/http/client/client_test.go
index 39dd807..9cf9520 100644
--- a/http/client/client_test.go
+++ b/http/client/client_test.go
@@ -73,6 +73,8 @@ func (r dummyReadCloser) Read(p []byte) (n int, err error) {
const (
contentJSON = "application/json"
dateLayout = "2006-01-02T15:04:05Z07:00"
+ invalidID = "test"
+ validUUID = "ec4898ac-0853-407c-8501-cbb24ef6bd77"
)
var (
@@ -829,12 +831,49 @@ func TestListWorkers(t *testing.T) {
}
func TestGetWorkerInfo(t *testing.T) {
- assert, client := initTest(t, "")
- assert.NotNil(client)
+ prefix := "worker-info-"
+ path := "/api/v1/workers/"
+ worker := newWorker(validUUID, IDLE, Groups{}, nil)
+ header := make(http.Header)
+ header.Set("Boruta-Worker-State", "IDLE")
+
+ tests := []*testCase{
+ &testCase{
+ // valid
+ name: prefix + "valid",
+ path: path + validUUID,
+ contentType: contentJSON,
+ status: http.StatusOK,
+ header: header,
+ },
+ &testCase{
+ // invalid UUID
+ name: prefix + "bad-uuid",
+ path: path + invalidID,
+ contentType: contentJSON,
+ status: http.StatusBadRequest,
+ },
+ }
- info, err := client.GetWorkerInfo(WorkerUUID(""))
+ srv := prepareServer(http.MethodGet, tests)
+ defer srv.Close()
+ assert, client := initTest(t, srv.URL)
+
+ // valid
+ info, err := client.GetWorkerInfo(validUUID)
+ assert.Nil(err)
+ assert.Equal(worker, info)
+
+ // invalid UUID
+ info, err = client.GetWorkerInfo(invalidID)
assert.Zero(info)
- assert.Equal(util.ErrNotImplemented, err)
+ assert.Equal(util.NewServerError(util.ErrBadUUID), err)
+
+ // http.Get failure
+ client.url = "http://nosuchaddress.fail"
+ info, err = client.GetWorkerInfo(validUUID)
+ assert.Zero(info)
+ assert.NotNil(err)
}
func TestSetState(t *testing.T) {