diff options
Diffstat (limited to 'k6-tests/ncmp/common/passthrough-crud.js')
-rw-r--r-- | k6-tests/ncmp/common/passthrough-crud.js | 38 |
1 files changed, 23 insertions, 15 deletions
diff --git a/k6-tests/ncmp/common/passthrough-crud.js b/k6-tests/ncmp/common/passthrough-crud.js index c5f2dddcf1..0cd96ad64d 100644 --- a/k6-tests/ncmp/common/passthrough-crud.js +++ b/k6-tests/ncmp/common/passthrough-crud.js @@ -18,33 +18,37 @@ * ============LICENSE_END========================================================= */ -import http from 'k6/http'; import { randomIntBetween } from 'https://jslib.k6.io/k6-utils/1.2.0/index.js'; -import { TOTAL_CM_HANDLES, CONTENT_TYPE_JSON_PARAM, NCMP_BASE_URL, TOPIC_DATA_OPERATIONS_BATCH_READ } from './utils.js'; +import { + performPostRequest, + performGetRequest, + NCMP_BASE_URL, + TOPIC_DATA_OPERATIONS_BATCH_READ, + TOTAL_CM_HANDLES +} from './utils.js'; export function passthroughRead(useAlternateId) { const cmHandleReference = getRandomCmHandleReference(useAlternateId); const resourceIdentifier = 'my-resource-identifier'; - const includeDescendants = true; const datastoreName = 'ncmp-datastore:passthrough-operational'; - const url = `${NCMP_BASE_URL}/ncmp/v1/ch/${cmHandleReference}/data/ds/${datastoreName}?resourceIdentifier=${resourceIdentifier}&include-descendants=${includeDescendants}` - const response = http.get(url); - return response; + const includeDescendants = true; + const url = generatePassthroughUrl(cmHandleReference, datastoreName, resourceIdentifier, includeDescendants); + return performGetRequest(url, 'passthroughRead'); } export function passthroughWrite(useAlternateId) { const cmHandleReference = getRandomCmHandleReference(useAlternateId); const resourceIdentifier = 'my-resource-identifier'; const datastoreName = 'ncmp-datastore:passthrough-running'; - const url = `${NCMP_BASE_URL}/ncmp/v1/ch/${cmHandleReference}/data/ds/${datastoreName}?resourceIdentifier=${resourceIdentifier}` - const body = `{"neType": "BaseStation"}` - const response = http.post(url, JSON.stringify(body), CONTENT_TYPE_JSON_PARAM); - return response; + const includeDescendants = false; + const url = generatePassthroughUrl(cmHandleReference, datastoreName, resourceIdentifier, includeDescendants); + const payload = JSON.stringify({"neType": "BaseStation"}); + return performPostRequest(url, payload, 'passthroughWrite'); } export function batchRead(cmHandleIds) { - const url = `${NCMP_BASE_URL}/ncmp/v1/data?topic=${TOPIC_DATA_OPERATIONS_BATCH_READ}` - const payload = { + const url = `${NCMP_BASE_URL}/ncmp/v1/data?topic=${TOPIC_DATA_OPERATIONS_BATCH_READ}`; + const payload = JSON.stringify({ "operations": [ { "resourceIdentifier": "parent/child", @@ -55,12 +59,16 @@ export function batchRead(cmHandleIds) { "operation": "read" } ] - }; - const response = http.post(url, JSON.stringify(payload), CONTENT_TYPE_JSON_PARAM); - return response; + }); + return performPostRequest(url, payload, 'batchRead'); } function getRandomCmHandleReference(useAlternateId) { const prefix = useAlternateId ? 'alt' : 'ch'; return `${prefix}-${randomIntBetween(1, TOTAL_CM_HANDLES)}`; } + +function generatePassthroughUrl(cmHandleReference, datastoreName, resourceIdentifier, includeDescendants) { + const descendantsParam = includeDescendants ? `&include-descendants=${includeDescendants}` : ''; + return `${NCMP_BASE_URL}/ncmp/v1/ch/${cmHandleReference}/data/ds/${datastoreName}?resourceIdentifier=${resourceIdentifier}${descendantsParam}`; +}
\ No newline at end of file |