-
This unit test will create an Index with Payload:
PUT
call to the endpoint/api/index
with{"name":"newindex","storage_type":"disk"}
in body.- Send a request to the server and response would be recorded.
- Using assert.Equal will test if the response code is equal to http.StatusOK (i.e 200),that means test is OK.
- Using assert.Equal will test the response message is euqal to the
{"index":"newindex","message":"ok","storage_type":"disk"}
, that means test is OK and index is created successfully.
-
This unit test will create an Index with error Input:
PUT
call to the endpoint/api/index
with{"name":"","storage_type":"disk"}
in body.- Send a request to the server and response would be recorded.
- Using assert.Equal will test if the response code is equal to http.StatusBadRequest (i.e 400),that means test is OK.
-
This unit test will get all the Indexes:
GET
call to the endpoint/api/index
.- Send a request to the server and response would be recorded.
- Using assert.Equal will test if the response code is equal to http.StatusOK (i.e 200),that means test is OK.
- Unmarshal the json response from the server and using assert.NoError to check there is no error and using assert.GreaterorEqual to check that the length of the response is greater or equal to 1.
-
This unit test will delete Index with existing Index:
DELETE
call to the endpoint/api/index/newindex
.- Send a request to the server and response would be recorded.
- Using assert.Equal will test if the response code is equal to http.StatusOK (i.e 200),that means test is OK and index is deleted.
-
This unit test will delete Index with no existing Index:
DELETE
call to the endpoint/api/index/newindex
.- As Index was already deleted in the above test , request is sent to the server and response is recorded.
- Using assert.Equal will test if the response code is equal to http.StatusBadRequest (i.e 400),that means test is OK.