Skip to content

Commit

Permalink
Added Test Documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
Usman762 authored and hengfeiyang committed Jul 4, 2022
1 parent 7f2b52e commit b348291
Show file tree
Hide file tree
Showing 27 changed files with 997 additions and 0 deletions.
212 changes: 212 additions & 0 deletions test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
# Unit Test Workflows
## Setting up the test enviroment (for etcd metadata storage)
1. Need to install **etcd** , add `root` user and enable authentication. You can use this [link](https://etcd.io/docs/v3.4/op-guide/authentication/) to setup etcd.
2. Update the root password in your .env file.
3. You are good to go.

## For boltdb, badger metadata storage

You just need to specify ZINC_METADATA_STORAGE environment variable to "bolt" or "badger" . Default value of ZINC_METADATA_STORAGE is "bolt"

## Steps to run tests
1. A bash script at project root named `test.sh` can be used to run these unit tests.
```sh
cd zinc
./test.sh
```
2. If you pass an argument `bench` then it will run the benchmark test.
```sh
./test.sh bench
```

## API Tests

### Testing Authentication (Test File : auth_test.go)
---
1. #### Testing Auth API
1. [Testing Authentication with Authorization](./test_docs/AUTH_API.md)
2. [Testing Authorization with error Password](.test_docs/AUTH_API.md)
3. [Testing Authentication without Authorization](.test_docs/AUTH_API.md)

2. #### Testing User API
1. [Testing Login with username and password](./test_docs/USER_AUTH_API.md)
2. [Testing Login with bad username or password](./test_docs/USER_AUTH_API.md)
3. [Testing Create User API](./test_docs/USER_AUTH_API.md)
4. [Test Update User](./test_docs/USER_AUTH_API.md)
5. [Test Create User with error Input](./test_docs/USER_AUTH_API.md)
6. [Test Delete User with existing UserID](./test_docs/USER_AUTH_API.md)
7. [Test Delete User with no existing UserID](./test_docs/USER_AUTH_API.md)
8. [Test GET User](./test_docs/USER_AUTH_API.md)
---
### Test Base API (Test File : base_test.go)
---
#### Base API Test
1. [Test Base API](./test_docs/BASE_API.md)
2. [Test Version API](./test_docs/BASE_API.md)
3. [Test Health API](./test_docs/BASE_API.md)
4. [Test User Interface API](./test_docs/BASE_API.md)
---

### Test Document Bulk (Test File : document_bulk_test.go)
---
1. #### Test Bulk Document with Endpoint /api/_bulk
1. [Test Bulk Document Index](./test_docs/BULK_API.md)
2. [Test Bulk Document Delete](./test_docs/BULK_API.md)
3. [Test Bulk Document with error Input](./test_docs/BULK_API.md)

2. #### Test Bulk Document with Enpoint /api/:target/_bulk
1. [Test Create Document with not existing Index](./test_docs/BULK_API_TARGET.md)
2. [Test Create Document with existing Index](./test_docs/BULK_API_TARGET.md)
3. [Test Bulk Document with error Input](./test_docs/BULK_API_TARGET.md)
---

### Test Document (Test File: document_test.go)
---
1. #### Test Create Document with Endpoint /api/:target/_doc
1. [Test Create Document with not existing Index](./test_docs/DOC_CREATE.md)
2. [Test Create Document with existing Index](./test_docs/DOC_CREATE.md)
3. [Test Create Document with existing Index and not existing Document ID](./test_docs/DOC_CREATE.md)
4. [Test Update Document with existing Index and existing Document ID](./test_docs/DOC_CREATE.md)
5. [Test Create Document with error Input](./test_docs/DOC_CREATE.md)

2. #### Test Update Document with Endpoint /api/:target/_doc/:id
1. [Test Update Document with no existing Index](./test_docs/DOC_UPDATE.md)
2. [Test Update Document with existing Index](./test_docs/DOC_UPDATE.md)
3. [Test Update Document with existing Index and not existing ID](./test_docs/DOC_UPDATE.md)
4. [Test Update Document with existing Index and existing ID](./test_docs/DOC_UPDATE.md)
5. [Test Update Document with error Input](./test_docs/DOC_UPDATE.md)

3. #### Test Delete Document with Endpoint /api/:target/_doc/:id
1. [Test Delete Document with not existing Index](./test_docs/DOC_DELETE.md)
2. [Test Delete Document with existing Index and not existing ID](./test_docs/DOC_DELETE.md)
3. [Test Delete Document with existing Index and existing ID](./test_docs/DOC_DELETE.md)
---

### Test Index (Test File : index_test.go)
---
1. #### Test Index with Endpoint /api/index
1. [Test Create Index with Payload](./test_docs/INDEX.md)
2. [Test Create Index with error Input](./test_docs/INDEX.md)
3. [Test GET Index](./test_docs/INDEX.md)
4. [Test Delete with existing Index](./test_docs/INDEX.md)
5. [Test Delete with not existing Index](./test_docs/INDEX.md)

2. #### Test Index Mapping with Endpoint /api/:target/_mapping
1. [Test Update mapping for Index](./test_docs/INDEX_MAP.md)
2. [Test GET mappings from Index](./test_docs/INDEX_MAP.md)

---

### Test ElasticSeacrch API (Test File : es_test.go)
---
1. #### Test ES API with Endpoint /es/_bulk
1. [Test Bulk Document Index](./test_docs/ES_API_1.md)
2. [Test Bulk Document Delete](./test_docs/ES_API_1.md)
3. [Test Bulk Document with error Input](./test_docs/ES_API_1.md)

2. #### Test ES API with Endpoint /es/:target/_bulk
1. [Test Create Document with no existing Index](./test_docs/ES_API_2.md)
2. [Test Create Document with existing Index](./test_docs/ES_API_2.md)
3. [Test Bulk with error Input](./test_docs/ES_API_2.md)

3. #### Test ES API with Endpoint /es/:target/_doc
1. [Test Create Document with not existing Index](./test_docs/ES_API_3.md)
2. [Test Create Document with existing Index](./test_docs/ES_API_3.md)
3. [Test Create Document with existing Index and not existing Document ID](./test_docs/ES_API_3.md)
4. [Test Update Document with existing Index and existing Document ID](./test_docs/ES_API_3.md)
5. [Test Create Document with error Input](./test_docs/ES_API_3.md)

4. #### Test ES API with Endpoint /es/:target/_doc/:id
1. [Test Update Document with no existing Index](./test_docs/ES_API_4.md)
2. [Test Update Document with existing Index](./test_docs/ES_API_4.md)
3. [Test Create Document with existing Index and not existing ID](./test_docs/ES_API_4.md)
4. [Test Update Document with existing Index and existing ID](./test_docs/ES_API_4.md)
5. [Test Update Document with error Input](./test_docs/ES_API_4.md)

5. #### Test ES API with Endpoint /es/:target/_doc/:id
1. [Test Delete Document with not existing Index](./test_docs/ES_API_5.md)
2. [Test Delete Document with existing Index and not existing ID](./test_docs/ES_API_5.md)
3. [Test Delete Document with existing Index and existing ID](./test_docs/ES_API_5.md)

6. #### Test ES API with Endpoint /es/:target/_create/:id (PUT)
1. [Test Update Document with no existing Index](./test_docs/ES_API_6.md)
2. [Test Update Document with existing Index](./test_docs/ES_API_6.md)
3. [Test Update Document with existing Index and not existing ID](./test_docs/ES_API_6.md)
4. [Test Update Document with existing Index and existing ID](./test_docs/ES_API_6.md)
5. [Test Update Document with error Input](./test_docs/ES_API_6.md)

7. #### Test ES API with Endpoint /es/:target/_create/:id (POST)
1. [Test Update Document with no existing Index](./test_docs/ES_API_7.md)
2. [Test Update Document with existing Index](./test_docs/ES_API_7.md)
3. [Test Update Document with existing Index and not existing ID](./test_docs/ES_API_7.md)
4. [Test Update Document with existing Index and existing ID](./test_docs/ES_API_7.md)
5. [Test Update Document with error Input](./test_docs/ES_API_7.md)

8. #### Test ES API with Endpoint /es/:target/_update/:id
1. [Test Update Document with no existing Index](./test_docs/ES_API_8.md)
2. [Test Update Document with existing Index](./test_docs/ES_API_8.md)
3. [Test Update Document with existing Index and not existing ID](./test_docs/ES_API_8.md)
4. [Test Update Document with existing Index and existing ID](./test_docs/ES_API_8.md)
5. [Test Update Document with error Input](./test_docs/ES_API_8.md)
---
### Test Document Searchv1 (Test File : search_v1_test.go)
---
1. #### Test Search with Endpoint /api/:target/_search
1. [Test Search Document with no existing Index](./test_docs/SEARCH_V1_1.md)
2. [Test Search Document with existing Index](./test_docs/SEARCH_V1_1.md)
3. [Test Search Document with no existing Term](./test_docs/SEARCH_V1_1.md)
4. [Test Search Document with existing Term](./test_docs/SEARCH_V1_1.md)
5. [Test Search Document with search type all documents](./test_docs/SEARCH_V1_1.md)
6. [Test Search Document with search type wildcard](./test_docs/SEARCH_V1_1.md)
7. [Test Search Document with search type fuzzy](./test_docs/SEARCH_V1_1.md)
8. [Test Search Document with search type term](./test_docs/SEARCH_V1_1.md)
9. [Test Search Document with search type data range](./test_docs/SEARCH_V1_1.md)
10. [Test Search Document with search type match all](./test_docs/SEARCH_V1_1.md)
11. [Test Search Document with search type match](./test_docs/SEARCH_V1_1.md)
12. [Test Search Document with search type match phrase](./test_docs/SEARCH_V1_1.md)
13. [Test Search Document with search type multiphrase](./test_docs/SEARCH_V1_1.md)
14. [Test Search Document with search type prefix](./test_docs/SEARCH_V1_1.md)
15. [Test Search Document with search type query string](./test_docs/SEARCH_V1_1.md)

2. #### Test Search Document with Aggregation
1. [Test Search Document with Term Aggregation](./test_docs/SEARCH_V1_2.md)
2. [Test Search Document with Metric Aggregation](./test_docs/SEARCH_V1_2.md)

---
### Test Document Searchv2 (Test File : search_v2_test.go)
---
1. #### Test Search Document with Endpoint /es/:target/_search
1. [Test Search Document with no existing Index](./test_docs/SEARCH_V2_1.md)
2. [Test Search Document with existing Index](./test_docs/SEARCH_V2_1.md)
3. [Test Search Document with no existing Term](./test_docs/SEARCH_V2_1.md)
4. [Test Search Document with existing Term](./test_docs/SEARCH_V2_1.md)
5. [Test Search Document with search type match all](./test_docs/SEARCH_V2_1.md)
6. [Test Search Document with search type wildcard](./test_docs/SEARCH_V2_1.md)
7. [Test Search Document with search type fuzzy](./test_docs/SEARCH_V2_1.md)
8. [Test Search Document with search type term](./test_docs/SEARCH_V2_1.md)
9. [Test Search Document with search type data range](./test_docs/SEARCH_V2_1.md)
10. [Test Search Document with search type match](./test_docs/SEARCH_V2_1.md)
11. [Test Search Document with search type match phrase](./test_docs/SEARCH_V2_1.md)
12. [Test Search Document with search type prefix](./test_docs/SEARCH_V2_1.md)
13. [Test Search Document with search type query string](./test_docs/SEARCH_V2_1.md)

2. #### Test Search Document with Aggregation
1. [Test Search Document with Term Aggregation](./test_docs/SEARCH_V2_2.md)
2. [Test Search Document with Metric Aggregation](./test_docs/SEARCH_V2_2.md)
---

### Test Analyzers (Test File : analyze_test.go)
---
1. #### [Test Analyzers](./test_docs/ANALYZER.md)
2. #### [Test Tokenizers](./test_docs/TOKENIZER.md)
3. #### [Test Token Filter](./test_docs/TOEKN_FILTER.md)

---

## Benchmark Test

### Test Benchmark (Test File : bulk_test.go)
---
1. #### [Test Bulk Worker Function](./test_docs/BENCH_BULK.md)
---

16 changes: 16 additions & 0 deletions test/test_docs/ANALYZER.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
## Test Analyzers
Analyzers are combination of tokenizers and token filters. Tokenizer split the text into terms and further filters are applied on the terms using specified token filters.
Below is the functionality of the Analyzer that are tested using TestAnalyzer with endpoint `/api/_analyze`:
|No. | Analyzer Name | Analyzer Functionality |
| -- | ---------------------------------------------- | ---------------- |
| 1 | Standard | Lower case alphabets|
| 2 | Standard Analyzer with stop words | Lower case alphabets and drop stop words|
| 3 | Standard Analyzer with stop words and filter | Lower case alphabets,drop stop words and apply specified filter|
| 4 | Simple | Lower case alphabets and drop numbers|
| 5 | Keyword | Accept the text and output the exact same text as a single term |
| 6 | Regexp | Lower case alphabets and drop characters (i.e ",#@ etc) |
| 7 | Regexp with pattern | Lower case alphabets and look for pattern to drop and tokenize accordingly|
| 8 | Stop | Lower case alphabets and drop stop words|
| 9 | Stop Analyzer with stop words | Lower case alphabets and drop specified words|
| 10 | Whitespace | Divide text to terms based on whitespace |
| 11 | Web | Lower case alphabets, drop stop words and identify URLs |
20 changes: 20 additions & 0 deletions test/test_docs/AUTH_API.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
## Testing Auth API
1. ### Testing Authentication with Authorization
This unit test will check authentication with user authorization:
1. `GET` call to endpoint `/api/index/`.
2. Setting Basic Auth that will set the request's Authorization header to use HTTP Basic Authentication with the provided username and password.
3. Send a request to the server and response would be recorded.
4. Using assert.Equal will test if the response code is equal to http.StatusOK (i.e 200),that means test is OK and user has the authorization.

2. ### Testing Authorization with Error Password
This unit test will check the user authorization with error password:
1. `GET` call to endpoint `/api/index/`.
2. Setting Basic Auth that will set the request's Authorization header to use HTTP Basic Authentication with the provided username and password {'xxx'}.
3. Send a request to the server and response would be recorded.
4. Using assert.Equal will test if the response code is equal to http.StatusUnauthorized (i.e 401),that means test is OK and authorization with error password is working fine.

3. ### Testing Authentication without Authorization
This unit test will check the authentication without user authorization:
1. `GET` call to endpoint `/api/index/`.
2. Send a request to the server and response would be recorded.
3. Using assert.Equal will test if the response code is equal to http.StatusUnauthorized (i.e 401),that means test is OK and authentication without authorization is working fine.
24 changes: 24 additions & 0 deletions test/test_docs/BASE_API.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
## Base API Test
1. ### Test Base API
This unit test will check the Zinc base API:
1. `GET ` call to the endpoint `/`.
2. Using assert.Equal will test if the response code is equal to http.StatusOK (i.e 200),that means test is OK.
2. ### Test Version API
This unit test will check the Zinc version:
1. `GET` call to the endpoint `/version`.
2. Send a request to the server and response would be recorded.
3. Using assert.Equal will test if the response code is equal to http.StatusOK (i.e 200),that means test is OK.
4. Unmarshal the json recieved in the response body and will check if there is no error using assert.NoError and using assert.True to check if the data has the field "Version".

3. ### Test Health API
This unit test will check the Zinc Server health:
1. `GET` call to the endpoint `/healthz`.
2. Send a request to the server and response would be recorded.
3. Using assert.Equal will test if the response code is equal to http.StatusOK (i.e 200),that means test is OK.
4. Unmarshal the json recieved in the response body and will check if there is no error using assert.NoError and using assert.True to check if the data has the field "Status"and using asset.Equal to check if the status is 'ok'.

4. ### Test User Interface API
This unit test will check the Zinc UI API:
1. `GET` call to the endpoint `/ui`.
2. Send a request to the server and response would be recorded.
3. Using assert.Equal will test if the response code is equal to http.StatusOK (i.e 200),that means test is OK.
5 changes: 5 additions & 0 deletions test/test_docs/BENCH_BULK.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## Test Bulk Worker Function
1. This benchmark test the BulkWorker function that takes target as an `Index` name and f as a `file name`.
2. The file should be in ndjson form.
3. Using os.Open to read the content of ndjson file.
4. A for loop whill run b.N times and examine the performance of the Bulk Worker Function code.
19 changes: 19 additions & 0 deletions test/test_docs/BULK_API.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## Test Bulk Document with Endpoint /api/_bulk

1. ### Test Bulk Document Index
This unit test will index documents in bulk:
1. `POST` call to the endpoint `/api/_bulk` with bulkData in body.
2. The **bulkData** will be in ndjson form defined in init.go.
3. Send a request to the server and response would be recorded.
4. Using assert.Equal will test if the response code is equal to http.StatusOK (i.e 200),that means test is OK and documents are indexed.
2. ### Test Bulk Document Delete
This unit test will delete documents in bulk:
1. `POST` call to the endpoint `/api/_bulk` with bulkDataWithDelete in body.
2. The **bulkDataWithDelete** will be in ndjson form defined in init.go.
3. Send a request to the server and response would be recorded.
4. Using assert.Equal will test if the response code is equal to http.StatusOK (i.e 200),that means test is OK and documents are deleted.
3. ### Test Bulk Document with Error Input
This unit test will index documents with error input:
1. `POST` call to the endpoint `/api/_bulk` with `{"index": {}}` in body .
2. Send a request to the server and response would be recorded.
3. Using assert.Equal will test if the response code is equal to http.StatusOK (i.e 200),that means test is OK.
20 changes: 20 additions & 0 deletions test/test_docs/BULK_API_TARGET.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
## Test Bulk Document with Enpoint /api/:target/_bulk

1. ### Test Create Document with not existing Index
This unit test will index documents with not existing index:
1. `POST` call to the endpoint `/api/notExistIndex/_bulk` with bulkData in body.
2. Send a request to the server and response would be recorded.
3. Using assert.Equal will test if the response code is equal to http.StatusOK (i.e 200),that means test is OK.
2. ### Test Create Document with Existing Index
This unit test will index documents with existing index:
1. `PUT` call to the endpoint `/api/index/` with `{"name": indexName", "storage_type": "disk"}` in body indexName defined in init.go.
2. Send a request to the server and response would be recorded and using assert.Equal will test if the response code is equal to http.StatusBadRequest (i.e 400).
3. Unmarshal the response and check there is no error using assert.Error method and using assert.Equal to check that the response is equal to **index ["+indexName+"] already exists**.
4. `POST` call to the endpoint `/api/indexName/_bulk` with bulkData in body.
5. Send a request to the server and response would be recorded.
6. Using assert.Equal will test if the response code is equal to http.StatusOK (i.e 200),that means test is OK.
3. ### Test Bulk Document with error input
This unit test will index bulk document with error input:
1. `POST` call to the endpoint `/api/indexName/_bulk` with `{"index": {}}` in body.
2. Send a request to the server and response would be recorded.
3. Using assert.Equal will test if the response code is equal to http.StatusOK (i.e 200),that means test is OK.
Loading

0 comments on commit b348291

Please sign in to comment.