HTTP API Client: Deregister worker 41/182241/7
authorMaciej Wereski <m.wereski@partner.samsung.com>
Thu, 21 Jun 2018 13:31:50 +0000 (15:31 +0200)
committerMaciej Wereski <m.wereski@partner.samsung.com>
Tue, 10 Jul 2018 08:01:25 +0000 (10:01 +0200)
Change-Id: I0a622bea2265ffbced657921d8cba03a97053cd9
Signed-off-by: Maciej Wereski <m.wereski@partner.samsung.com>
http/client/client.go
http/client/client_test.go

index b6eee86..b656f9e 100644 (file)
@@ -345,5 +345,10 @@ func (client *BorutaClient) SetGroups(uuid boruta.WorkerUUID, groups boruta.Grou
 // Deregister requests Boruta server to deregister worker with provided UUID.
 // Deregister is intended only for Boruta server administrators.
 func (client *BorutaClient) Deregister(uuid boruta.WorkerUUID) error {
-       return util.ErrNotImplemented
+       path := client.url + "workers/" + string(uuid) + "/deregister"
+       resp, err := http.Post(path, "", nil)
+       if err != nil {
+               return err
+       }
+       return processResponse(resp, nil)
 }
index 74359bd..1fa244d 100644 (file)
@@ -954,9 +954,37 @@ func TestSetGroups(t *testing.T) {
 }
 
 func TestDeregister(t *testing.T) {
-       assert, client := initTest(t, "")
-       assert.NotNil(client)
+       prefix := "worker-deregister-"
+       path := "/api/v1/workers/"
+
+       tests := []*testCase{
+               &testCase{
+                       // valid
+                       name:        prefix + "valid",
+                       path:        path + validUUID + "/deregister",
+                       contentType: contentJSON,
+                       status:      http.StatusNoContent,
+               },
+               &testCase{
+                       // invalid UUID
+                       name:        prefix + "bad-uuid",
+                       path:        path + invalidID + "/deregister",
+                       contentType: contentJSON,
+                       status:      http.StatusBadRequest,
+               },
+       }
+
+       srv := prepareServer(http.MethodPost, tests)
+       defer srv.Close()
+       assert, client := initTest(t, srv.URL)
+
+       // valid
+       assert.Nil(client.Deregister(validUUID))
 
-       err := client.Deregister(WorkerUUID(""))
-       assert.Equal(util.ErrNotImplemented, err)
+       // invalid UUID
+       assert.Equal(util.NewServerError(util.ErrBadUUID), client.Deregister(invalidID))
+
+       // http.Post failure
+       client.url = "http://nosuchaddress.fail"
+       assert.NotNil(client.Deregister(validUUID))
 }