Skip to content

Commit

Permalink
Merge pull request #905 from cherrycl/issue-899-implement
Browse files Browse the repository at this point in the history
feat: Implement tests for core-keeper
  • Loading branch information
cloudxxx8 authored Jul 30, 2024
2 parents 453c10c + 944d726 commit 0a9c5f1
Show file tree
Hide file tree
Showing 11 changed files with 277 additions and 79 deletions.
6 changes: 4 additions & 2 deletions TAF/testCaseModules/keywords/common/commonKeywords.robot
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,9 @@ Update Service Configuration On Keeper
Create Session Keeper url=${url} disable_warnings=true
${body} Create Dictionary value=${value}
${resp}= PUT On Session Keeper ${KEEPER_CONFIG_BASE_ENDPOINT}/${path}
... json=${body} headers=${headers} expected_status=200
... json=${body} headers=${headers} expected_status=any
Sleep 1s # Waiting for the configuration updating
Set Response to Test Variables ${resp}

Query Service Configuration On Keeper
[Arguments] ${path}
Expand All @@ -297,7 +298,8 @@ Delete Service Configuration On Keeper
${url} Set Variable ${URI_SCHEME}://${BASE_URL}:${CORE_KEEPER_PORT}
Create Session Keeper url=${url} disable_warnings=true
${resp}= DELETE On Session Keeper ${KEEPER_CONFIG_BASE_ENDPOINT}/${path}
... headers=${headers} expected_status=200
... headers=${headers} expected_status=any
Set Response to Test Variables ${resp}

Update Configuration On Registry Service
[Arguments] ${path} ${value}
Expand Down
63 changes: 63 additions & 0 deletions TAF/testCaseModules/keywords/core-keeper/coreKeeperAPI.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
*** Settings ***
Library RequestsLibrary
Resource TAF/testCaseModules/keywords/core-keeper/coreKeeperAPI.robot
Resource TAF/testCaseModules/keywords/common/commonKeywords.robot

*** Variables ***
${coreKeeperUrl} ${URI_SCHEME}://${BASE_URL}:${CORE_KEEPER_PORT}
${coreKeeperRegUri} /api/${API_VERSION}/registry
${coreKeeperKVsUri} /api/${API_VERSION}/kvs/key

*** Keywords ***
Generate Registry Data
[Arguments] ${serviceId} ${host} ${port}
${data} Get File ${WORK_DIR}/TAF/testData/core-keeper/registry_data.json encoding=UTF-8
${registry_data} Evaluate json.loads('''${data}''') json
${json} Create Dictionary registration=${registry_data}
Set to dictionary ${json} apiVersion=${API_VERSION}
Set To Dictionary ${json}[registration] serviceId=${serviceId}
Set To Dictionary ${json}[registration] host=${host}
Set To Dictionary ${json}[registration] port=${port}
Set Test Variable ${Registry} ${json}

Register A New Service
[Arguments] ${entity}
Create Session Core Keeper url=${coreKeeperUrl} disable_warnings=true
${headers} Create Dictionary Content-Type=application/json Authorization=Bearer ${jwt_token}
${resp} POST On Session Core Keeper ${coreKeeperRegUri} json=${entity} headers=${headers}
... expected_status=any
Set Response to Test Variables ${resp}

Deregister Service
[Arguments] ${serviceId}
Create Session Core Keeper url=${coreKeeperUrl} disable_warnings=true
${headers} Create Dictionary Authorization=Bearer ${jwt_token}
${resp} DELETE On Session Core Keeper ${coreKeeperRegUri}/serviceId/${serviceId} headers=${headers}
... expected_status=any
run keyword if ${resp.status_code}!=204 log to console ${resp.content}
Set Response to Test Variables ${resp}

Query All Registered Services
Create Session Core Keeper url=${coreKeeperUrl} disable_warnings=true
${headers} Create Dictionary Content-Type=application/json Authorization=Bearer ${jwt_token}
${resp} GET On Session Core Keeper ${coreKeeperRegUri}/all headers=${headers}
... expected_status=any
Set Response to Test Variables ${resp}

Query Registered Service By ServiceId
[Arguments] ${serviceId}
Create Session Core Keeper url=${coreKeeperUrl} disable_warnings=true
${headers} Create Dictionary Content-Type=application/json Authorization=Bearer ${jwt_token}
${resp} GET On Session Core Keeper ${coreKeeperRegUri}/serviceId/${serviceId} headers=${headers}
... expected_status=any
Set Response to Test Variables ${resp}

Update Registered Service
[Arguments] ${entity}
Create Session Core Keeper url=${coreKeeperUrl} disable_warnings=true
${headers} Create Dictionary Content-Type=application/json Authorization=Bearer ${jwt_token}
${resp} PUT On Session Core Keeper ${coreKeeperRegUri} json=${entity} headers=${headers}
... expected_status=any
Set Response to Test Variables ${resp}


10 changes: 10 additions & 0 deletions TAF/testData/core-keeper/registry_data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"serviceId": "",
"host": "",
"port": 0,
"healthCheck": {
"interval": "10s",
"path": "/api/v3/ping",
"type": "http"
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
*** Settings ***
Resource TAF/testCaseModules/keywords/common/commonKeywords.robot
Resource TAF/testCaseModules/keywords/core-keeper/coreKeeperAPI.robot
Suite Setup Run Keywords Setup Suite
... AND Run Keyword if $SECURITY_SERVICE_NEEDED == 'true' Get Token
Suite Teardown Run Teardown Keywords
Force Tags Skipped

*** Variables ***
${SUITE} Core Keeper Info GET Test Cases
${LOG_FILE_PATH} ${WORK_DIR}/TAF/testArtifacts/logs/core-keeper-info.log
${url} ${coreKeeperUrl}

*** Test Cases ***
InfoGET001 - Query ping
Expand All @@ -27,4 +28,3 @@ InfoGET003 - Query config
Then Should Return Status Code "200" And config
And apiVersion Should be ${API_VERSION}
And Response Time Should Be Less Than "${default_response_time_threshold}"ms

20 changes: 13 additions & 7 deletions TAF/testScenarios/functionalTest/API/core-keeper/kvs/DELETE.robot
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,37 @@ Resource TAF/testCaseModules/keywords/common/commonKeywords.robot
Suite Setup Run Keywords Setup Suite
... AND Run Keyword if $SECURITY_SERVICE_NEEDED == 'true' Get Token
Suite Teardown Run Teardown Keywords
Force Tags Skipped

*** Variables ***
${SUITE} Core Keeper Key/Value DELETE Test Cases
${LOG_FILE_PATH} ${WORK_DIR}/TAF/testArtifacts/logs/core-keeper-kvs-delete.log

*** Test Cases ***
KVsDELETE001 - Delete an existed configuration
Given Create New Configuration
When Delete An Existed Configuration
Given Set Test Variable ${path} testKVsDelService/Writable/Key1
And Set Test Variable ${set_value} value1
And Update Service Configuration On Keeper ${path} ${set_value}
When Delete Service Configuration On Keeper ${path}
Then Should Return Status Code "200" And response
And apiVersion Should be ${API_VERSION}
And Response Time Should Be Less Than "${default_response_time_threshold}"ms
And Configuration Should Not Exist

ErrKVsDELETE001 - Should return error when deleting an absent configuration
# "value":"test"
When Delete An Absent Configuration
When Delete Service Configuration On Keeper testKVsDelService/Writable/KeyAbsent
Then Should Return Status Code "404"
And Should Return Content-Type "application/json"
And Response Time Should Be Less Than "${default_response_time_threshold}"ms

ErrKVsDELETE002 - Should return error when deleting configuration which contains associated configuration
# { key: value }
When Delete a Configuration Which Contains Associated Configuration
Given Set Test Variable ${path} testKVsDelService/Writable
And Update Service Configuration On Keeper ${path}/Key1 value1
When Delete Service Configuration On Keeper ${path}
Then Should Return Status Code "409"
And Should Return Content-Type "application/json"
And Response Time Should Be Less Than "${default_response_time_threshold}"ms

*** Keywords ***
Configuration Should Not Exist
Query Service Configuration On Keeper ${path}
Should Return Status Code "404"
40 changes: 34 additions & 6 deletions TAF/testScenarios/functionalTest/API/core-keeper/kvs/GET.robot
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,57 @@ Resource TAF/testCaseModules/keywords/common/commonKeywords.robot
Suite Setup Run Keywords Setup Suite
... AND Run Keyword if $SECURITY_SERVICE_NEEDED == 'true' Get Token
Suite Teardown Run Teardown Keywords
Force Tags Skipped

*** Variables ***
${SUITE} Core Keeper Key/Value GET Test Cases
${LOG_FILE_PATH} ${WORK_DIR}/TAF/testArtifacts/logs/core-keeper-kvs-get.log

*** Test Cases ***
KVsGET001 - Value should be returned when query by configuration name(key)
When Query Configuration By Key
Given Set Test Variable ${path} testKVsGetService/Writable/key
And Update Service Configuration On Keeper ${path} value
When Query Service Configuration On Keeper ${path}
Then Should Return Status Code "200" And response
And Configuration Value Should Be Correct
And apiVersion Should be ${API_VERSION}
And Response Time Should Be Less Than "${default_response_time_threshold}"ms
And Should Be Equal As Strings ${content}[response][0][key] edgex/${CONFIG_VERSION}/${path}
[Teardown] Delete Service Configuration On Keeper ${path}

KVsGET002 - Only service configurations are listed if query by service level
When Query Configuration By Service Level
Given Set Test Variable ${service} testKVsGetService
And Add Multiple Configurations
When Query Service Configuration On Keeper ${service}
Then Should Return Status Code "200" And response
And Only Service Configurations Are Listed
And apiVersion Should be ${API_VERSION}
And Response Time Should Be Less Than "${default_response_time_threshold}"ms
And Only Service Configurations Are Listed
[Teardown] Delete Multiple Configurations

ErrKVsGET001 - Should return error when query by invalid configuration name(key)
When Query Configuration By Invalid Key
When Query Service Configuration On Keeper testKVsGetServiceErr/invalidKey
Then Should Return Status Code "404"
And Should Return Content-Type "application/json"
And Response Time Should Be Less Than "${default_response_time_threshold}"ms

*** Keywords ***
Only Service Configurations Are Listed
${count} Get Length ${content}[response]
FOR ${INDEX} IN RANGE ${count}
Should Match Regexp ${content}[response][${INDEX}][key] edgex\/${CONFIG_VERSION}\/${service}\/*
... msg=${content}[response][${INDEX}][key] does not belong to ${service}
END

Add Multiple Configurations
${path} Set Variable ${service}/Writable
${key_list} Create List key1 key2 key3
${value_list} Create List value1 value2 value3
FOR ${key} ${value} IN ZIP ${key_list} ${value_list}
Update Service Configuration On Keeper ${path}/${key} ${value}
END
Set Test Variable ${key_list} ${key_list}
Set Test Variable ${path} ${path}

Delete Multiple Configurations
FOR ${key} IN @{key_list}
Delete Service Configuration On Keeper ${path}/${key}
END
39 changes: 25 additions & 14 deletions TAF/testScenarios/functionalTest/API/core-keeper/kvs/PUT.robot
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,51 @@ Resource TAF/testCaseModules/keywords/common/commonKeywords.robot
Suite Setup Run Keywords Setup Suite
... AND Run Keyword if $SECURITY_SERVICE_NEEDED == 'true' Get Token
Suite Teardown Run Teardown Keywords
Force Tags Skipped

*** Variables ***
${SUITE} Core Keeper Key/Value PUT Test Cases
${LOG_FILE_PATH} ${WORK_DIR}/TAF/testArtifacts/logs/core-keeper-kvs-put.log

*** Test Cases ***
KVsPUT001 - Create a new configuration
When Create New Configuration
Given Set Test Variable ${path} testKVsPutService/Writable/LogLevel
And Set Test Variable ${set_value} ERROR
When Update Service Configuration On Keeper ${path} ${set_value}
Then Should Return Status Code "200" And response
And apiVersion Should be ${API_VERSION}
And Response Time Should Be Less Than "${default_response_time_threshold}"ms
And Query Configuration And Value Should Be Correct
[Teardown] Delete Configuration
[Teardown] Delete Service Configuration On Keeper ${path}

KVsPUT002 - Update a existed configuration and validate value should be updated
Given Create New Configuration
When Update A Exited Configuration
Given Set Test Variable ${path} testKVsPutService/Writable/LogLevel
And Update Service Configuration On Keeper ${path} ERROR
And Set Test Variable ${set_value} WARN
When Update Service Configuration On Keeper ${path} ${set_value}
Then Should Return Status Code "200" And response
And apiVersion Should be ${API_VERSION}
And Response Time Should Be Less Than "${default_response_time_threshold}"ms
And Query Configuration And Value Should Be Correct
[Teardown] Delete Configuration
[Teardown] Delete Service Configuration On Keeper ${path}

ErrKVsPUT001 - Should return error when updating configuration without JSON body
# "value":"test"
When Update A Exited Configuration Without JSON Body
When Update Configuration testKVsPutService/Writable/LogLevel key:value
Then Should Return Status Code "400"
And Should Return Content-Type "application/json"
And Response Time Should Be Less Than "${default_response_time_threshold}"ms

ErrKVsPUT002 - Should return error when updating configuration with invalid JSON format
# { key: value }
When Update A Exited Configuration Without JSON Body
Then Should Return Status Code "500"
And Should Return Content-Type "application/json"
And Response Time Should Be Less Than "${default_response_time_threshold}"ms
*** Keywords ***
Query Configuration And Value Should Be Correct
Query Service Configuration On Keeper ${path}
${decode_value} Evaluate base64.b64decode('${content}[response][0][value]').decode('utf-8') modules=base64
Should Be Equal As Strings ${set_value} ${decode_value}

Update Configuration
[Arguments] ${path} ${body}
${headers} Create Dictionary Authorization=Bearer ${jwt_token}
${url} Set Variable ${URI_SCHEME}://${BASE_URL}:${CORE_KEEPER_PORT}
Create Session Keeper url=${url} disable_warnings=true
${resp} PUT On Session Keeper ${KEEPER_CONFIG_BASE_ENDPOINT}/${path}
... json=${body} headers=${headers} expected_status=any
Set Response to Test Variables ${resp}

Original file line number Diff line number Diff line change
@@ -1,22 +1,31 @@
*** Settings ***
Resource TAF/testCaseModules/keywords/common/commonKeywords.robot
Resource TAF/testCaseModules/keywords/core-keeper/coreKeeperAPI.robot
Suite Setup Run Keywords Setup Suite
... AND Run Keyword if $SECURITY_SERVICE_NEEDED == 'true' Get Token
Suite Teardown Run Teardown Keywords
Force Tags Skipped

*** Variables ***
${SUITE} Core Keeper Registry DELETE Test Cases
${LOG_FILE_PATH} ${WORK_DIR}/TAF/testArtifacts/logs/core-keeper-registry-delete.log

*** Test Cases ***
RegistryDELETE001 - Delete a registered service
When Delete A Registered Service
RegistryDELETE001 - Deregister Service
Given Set Test Variable ${serviceId} testRegistryDelService
And Generate Registry Data ${serviceId} test-service-host ${12345}
And Register A New Service ${Registry}
When Deregister Service ${serviceId}
Then Should Return Status Code "204"
And Response Time Should Be Less Than "${default_response_time_threshold}"ms
And Service Should Be Deregistered

ErrRegistryDELETE001 - Delete an unregistered service
When Delete An Unregistered Service
When Deregister Service not_registry_service
Then Should Return Status Code "404"
And Should Return Content-Type "application/json"
And Response Time Should Be Less Than "${default_response_time_threshold}"ms

*** Keywords ***
Service Should Be Deregistered
Query Registered Service By ServiceId ${serviceId}
Should Return Status Code "404"
Original file line number Diff line number Diff line change
@@ -1,31 +1,56 @@
*** Settings ***
Resource TAF/testCaseModules/keywords/common/commonKeywords.robot
Resource TAF/testCaseModules/keywords/core-keeper/coreKeeperAPI.robot
Suite Setup Run Keywords Setup Suite
... AND Run Keyword if $SECURITY_SERVICE_NEEDED == 'true' Get Token
Suite Teardown Run Teardown Keywords
Force Tags Skipped

*** Variables ***
${SUITE} Core Keeper Registry GET Test Cases
${LOG_FILE_PATH} ${WORK_DIR}/TAF/testArtifacts/logs/core-keeper-registry-get.log

*** Test Cases ***
RegistryGET001 - Query all registered services
Given Register Multiple Services
When Query All Registered Services
Then Should Return Status Code "200" And registrations
And apiVersion Should be ${API_VERSION}
And Response Time Should Be Less Than "${default_response_time_threshold}"ms
And All Registered Services Are Listed And Count Should Match totalCount
[Teardown] Deregister Multiple Configurations

RegistryGET002 - Query registered service by name
When Query Registered Service By Name
Then Should Return Status Code "200" And registrations
RegistryGET002 - Query registered service by serviceId
Given Set Test Variable ${serviceId} testRegistryGetService
And Generate Registry Data ${serviceId} test-service-host ${12345}
And Register A New Service ${Registry}
When Query Registered Service By ServiceId ${serviceId}
Then Should Return Status Code "200" And registration
And apiVersion Should be ${API_VERSION}
And Response Time Should Be Less Than "${default_response_time_threshold}"ms
And Registered Service Should Be Found
And Should Be Equal As Strings ${serviceId} ${content}[registration][serviceId]
[Teardown] Deregister Service ${serviceId}

ErrRegistryGET001 - Should return error when querying unregistered service
When Query Unregistered Service
When Query Registered Service By ServiceId unregistered_service
Then Should Return Status Code "404"
And Should Return Content-Type "application/json"
And Response Time Should Be Less Than "${default_response_time_threshold}"ms

*** Keywords ***
All Registered Services Are Listed And Count Should Match totalCount
${service_count} Get Length ${content}[registrations]
Should Be Equal As Integers ${service_count} ${content}[totalCount]

Register Multiple Services
${Ids} Create List service1 service2 service3
FOR ${id} IN @{Ids}
Generate Registry Data ${id} ${id}-host ${12345}
Register A New Service ${Registry}
END
Set Test Variable ${serviceIds} ${Ids}

Deregister Multiple Configurations
FOR ${id} IN @{serviceIds}
Deregister Service ${id}
END

Loading

0 comments on commit 0a9c5f1

Please sign in to comment.