// 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)
}
}
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))
}