Skip to content
This repository has been archived by the owner on Jul 4, 2024. It is now read-only.

Commit

Permalink
Merge branch 'main' into data-center-aggrregation-support
Browse files Browse the repository at this point in the history
  • Loading branch information
NickyMateev committed Apr 15, 2024
2 parents 6a8c163 + 6ad1b16 commit f329eb6
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 32 deletions.
2 changes: 1 addition & 1 deletion chart/compass/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ global:
name: compass-operations-controller
ord_service:
dir: dev/incubator/
version: "PR-130"
version: "PR-131"
name: compass-ord-service
schema_migrator:
dir: dev/incubator/
Expand Down
10 changes: 2 additions & 8 deletions installation/scripts/prow/compass-smoke-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,8 @@ check_value "${GET_BUNDLE_1_EVENT_DEF_1}" "Event Def with ID: ${CRT_BUNDLE_1_EVE
GET_BUNDLE_1_EVENT_DEF_1_ID=$(echo -E ${GET_BUNDLE_1_EVENT_DEF_1} | jq -r '.id')
compare_values "${CRT_BUNDLE_1_EVENT_DEF_1_ID}" "${GET_BUNDLE_1_EVENT_DEF_1_ID}" "Application bundles Event Definitions IDs did not match. On creation: ${CRT_BUNDLE_1_EVENT_DEF_1_ID}. From Compass get: ${GET_BUNDLE_1_EVENT_DEF_1_ID}"


GET_APPS_FROM_ORD_RESULT=$(curl --request GET --url "${ORD_URL}/open-resource-discovery-service/v0/systemInstances?%24expand=consumptionBundles(%24expand%3Dapis%2Cevents)&%24format=json" --header "authorization: Bearer ${DIRECTOR_TOKEN}" --header "tenant: ${INTERNAL_TENANT_ID}")
# decoded query: /v0/systemInstances?$expand=consumptionBundles($select=id,title;$expand=events($select=id,title),apis($select=id,title))&$format=json
GET_APPS_FROM_ORD_RESULT=$(curl --request GET --url "${ORD_URL}/open-resource-discovery-service/v0/systemInstances?%24expand=consumptionBundles(%24select%3Did%2Ctitle;%24expand%3Devents(%24select%3Did%2Ctitle)%2Capis(%24select%3Did%2Ctitle))&%24format=json" --header "authorization: Bearer ${DIRECTOR_TOKEN}" --header "tenant: ${INTERNAL_TENANT_ID}")

echo "Result from get bundles request:"
echo "---------------------------------"
Expand All @@ -362,9 +362,6 @@ compare_values "${CRT_BUNDLES_COUNT}" "${ORD_BUNDLES_COUNT}" "Application bundle
ORD_BUNDLE_0=$(echo -E ${ORD_APP} | jq -c --arg bundleid ${CRT_BUNDLE_0_ID} '.consumptionBundles[] | select(.id==$bundleid)')
check_value "${ORD_BUNDLE_0}" "Bundle with ID: ${CRT_BUNDLE_0_ID} not found in ORD service"

ORD_BUNDLE_0=$(echo -E ${ORD_APP} | jq -c --arg bundleid ${CRT_BUNDLE_0_ID} '.consumptionBundles[] | select(.id==$bundleid)')
check_value "${ORD_BUNDLE_0}" "Bundle with ID: ${CRT_BUNDLE_0_ID} not found in ORD service"

ORD_BUNDLE_0_ID=$(echo -E ${ORD_BUNDLE_0} | jq -r '.id')
compare_values "${CRT_BUNDLE_0_ID}" "${ORD_BUNDLE_0_ID}" "Bundle IDs did not match. On creation: ${CRT_BUNDLE_0_ID}. From ORD service get: ${ORD_BUNDLE_0_ID}"

Expand Down Expand Up @@ -407,9 +404,6 @@ compare_values "${CRT_BUNDLE_0_EVENT_DEF_1_ID}" "${ORD_BUNDLE_0_EVENT_DEF_1_ID}"
ORD_BUNDLE_1=$(echo -E ${ORD_APP} | jq -c --arg bundleid ${CRT_BUNDLE_1_ID} '.consumptionBundles[] | select(.id==$bundleid)')
check_value "${ORD_BUNDLE_1}" "Bundle with ID: ${CRT_BUNDLE_1_ID} not found in ORD service"

ORD_BUNDLE_1=$(echo -E ${ORD_APP} | jq -c --arg bundleid ${CRT_BUNDLE_1_ID} '.consumptionBundles[] | select(.id==$bundleid)')
check_value "${ORD_BUNDLE_1}" "Bundle with ID: ${CRT_BUNDLE_1_ID} not found in ORD service"

ORD_BUNDLE_1_ID=$(echo -E ${ORD_BUNDLE_1} | jq -r '.id')
compare_values "${CRT_BUNDLE_1_ID}" "${ORD_BUNDLE_1_ID}" "Bundle IDs did not match. On creation: ${CRT_BUNDLE_1_ID}. From ORD service get: ${ORD_BUNDLE_1_ID}"

Expand Down
66 changes: 49 additions & 17 deletions tests/ord-service/tests/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ func TestORDService(t *testing.T) {

t.Run("400 when requests to ORD Service do not have tenant header", func(t *testing.T) {
params := url.Values{}
params.Add("$select", "id,title")
params.Add("$format", "json")

serviceURL := conf.ORDServiceURL + "/consumptionBundles?" + params.Encode()
Expand All @@ -182,6 +183,7 @@ func TestORDService(t *testing.T) {

t.Run("400 when requests to ORD Service have wrong tenant header", func(t *testing.T) {
params := url.Values{}
params.Add("$select", "id,title")
params.Add("$format", "json")

serviceURL := conf.ORDServiceURL + "/consumptionBundles?" + params.Encode()
Expand All @@ -190,6 +192,7 @@ func TestORDService(t *testing.T) {

t.Run("400 when requests to ORD Service api specification do not have tenant header", func(t *testing.T) {
params := url.Values{}
params.Add("$select", "id,resourceDefinitions")
params.Add("$format", "json")

serviceURL := conf.ORDServiceURL + "/apis?" + params.Encode()
Expand All @@ -205,6 +208,7 @@ func TestORDService(t *testing.T) {

t.Run("400 when requests to ORD Service event specification do not have tenant header", func(t *testing.T) {
params := url.Values{}
params.Add("$select", "id,resourceDefinitions")
params.Add("$format", "json")

serviceURL := conf.ORDServiceURL + "/events?" + params.Encode()
Expand All @@ -220,6 +224,7 @@ func TestORDService(t *testing.T) {

t.Run("400 when requests to ORD Service api specification have wrong tenant header", func(t *testing.T) {
params := url.Values{}
params.Add("$select", "id,resourceDefinitions")
params.Add("$format", "json")

serviceURL := conf.ORDServiceURL + "/apis?" + params.Encode()
Expand All @@ -235,6 +240,7 @@ func TestORDService(t *testing.T) {

t.Run("400 when requests to ORD Service event specification have wrong tenant header", func(t *testing.T) {
params := url.Values{}
params.Add("$select", "id,resourceDefinitions")
params.Add("$format", "json")

serviceURL := conf.ORDServiceURL + "/events?" + params.Encode()
Expand All @@ -249,11 +255,19 @@ func TestORDService(t *testing.T) {
})

t.Run("Requesting entities without specifying response format falls back to configured default response type when Accept header allows everything", func(t *testing.T) {
makeRequestWithHeaders(t, intSystemHttpClient, conf.ORDServiceURL+"/consumptionBundles", map[string][]string{acceptHeader: {"*/*"}, tenantHeader: {defaultTestTenant}})
params := url.Values{}
params.Add("$select", "id,title")
serviceURL := conf.ORDServiceURL + "/consumptionBundles?" + params.Encode()

makeRequestWithHeaders(t, intSystemHttpClient, serviceURL, map[string][]string{acceptHeader: {"*/*"}, tenantHeader: {defaultTestTenant}})
})

t.Run("Requesting entities without specifying response format falls back to response type specified by Accept header when it provides a specific type", func(t *testing.T) {
makeRequestWithHeaders(t, intSystemHttpClient, conf.ORDServiceURL+"/consumptionBundles", map[string][]string{acceptHeader: {"application/json"}, tenantHeader: {defaultTestTenant}})
params := url.Values{}
params.Add("$select", "id,title")
serviceURL := conf.ORDServiceURL + "/consumptionBundles?" + params.Encode()

makeRequestWithHeaders(t, intSystemHttpClient, serviceURL, map[string][]string{acceptHeader: {"application/json"}, tenantHeader: {defaultTestTenant}})
})

t.Run("Requesting Packages returns empty", func(t *testing.T) {
Expand All @@ -269,7 +283,8 @@ func TestORDService(t *testing.T) {
t.Run("Requesting filtering of Bundles that do not have only ODATA APIs", func(t *testing.T) {
params := url.Values{}
params.Add("$filter", "apis/any(d:d/apiProtocol ne 'odata-v2')")
params.Add("$expand", "apis")
params.Add("$select", "title,description")
params.Add("$expand", "apis($select=apiProtocol)")
params.Add("$format", "json")

serviceURL := conf.ORDServiceURL + "/consumptionBundles?" + strings.ReplaceAll(params.Encode(), "+", "%20")
Expand Down Expand Up @@ -297,7 +312,8 @@ func TestORDService(t *testing.T) {
t.Run("Requesting filtering of Bundles that have only ODATA APIs", func(t *testing.T) {
params := url.Values{}
params.Add("$filter", "apis/all(d:d/apiProtocol eq 'odata-v2')")
params.Add("$expand", "apis")
params.Add("$select", "title,description")
params.Add("$expand", "apis($select=apiProtocol)")
params.Add("$format", "json")

serviceURL := conf.ORDServiceURL + "/consumptionBundles?" + strings.ReplaceAll(params.Encode(), "+", "%20")
Expand Down Expand Up @@ -413,7 +429,7 @@ func TestORDService(t *testing.T) {

t.Run(fmt.Sprintf("Requesting System Instances with apis for tenant %s returns them as expected", testData.msg), func(t *testing.T) {
params := url.Values{}
params.Add("$expand", "apis")
params.Add("$expand", "apis($select=id,title,description,entryPoints,partOfConsumptionBundles,releaseStatus,apiProtocol,resourceDefinitions)")
params.Add("$format", "json")

respBody := makeRequestWithHeadersAndQueryParams(t, testData.client, testData.url+"/systemInstances?", testData.headers, params)
Expand All @@ -426,7 +442,7 @@ func TestORDService(t *testing.T) {

t.Run(fmt.Sprintf("Requesting System Instances with events for tenant %s returns them as expected", testData.msg), func(t *testing.T) {
params := url.Values{}
params.Add("$expand", "events")
params.Add("$expand", "events($select=id,title,description,partOfConsumptionBundles,releaseStatus,resourceDefinitions)")
params.Add("$format", "json")

respBody := makeRequestWithHeadersAndQueryParams(t, testData.client, testData.url+"/systemInstances?", testData.headers, params)
Expand All @@ -439,6 +455,7 @@ func TestORDService(t *testing.T) {

t.Run(fmt.Sprintf("Requesting Bundles for tenant %s returns them as expected", testData.msg), func(t *testing.T) {
params := url.Values{}
params.Add("$select", "title,description")
params.Add("$format", "json")

respBody := makeRequestWithHeadersAndQueryParams(t, testData.client, testData.url+"/consumptionBundles?", testData.headers, params)
Expand All @@ -450,6 +467,7 @@ func TestORDService(t *testing.T) {

t.Run(fmt.Sprintf("Requesting APIs and their specs for tenant %s returns them as expected", testData.msg), func(t *testing.T) {
params := url.Values{}
params.Add("$select", "id,title,description,entryPoints,partOfConsumptionBundles,releaseStatus,apiProtocol,resourceDefinitions")
params.Add("$format", "json")

respBody := makeRequestWithHeadersAndQueryParams(t, testData.client, testData.url+"/apis?", testData.headers, params)
Expand All @@ -459,6 +477,7 @@ func TestORDService(t *testing.T) {

t.Run(fmt.Sprintf("Requesting Events and their specs for tenant %s returns them as expected", testData.msg), func(t *testing.T) {
params := url.Values{}
params.Add("$select", "id,title,description,partOfConsumptionBundles,releaseStatus,resourceDefinitions")
params.Add("$format", "json")

respBody := makeRequestWithHeadersAndQueryParams(t, testData.client, testData.url+"/events?", testData.headers, params)
Expand All @@ -472,6 +491,7 @@ func TestORDService(t *testing.T) {
params := url.Values{}
params.Add("$top", "10")
params.Add("$skip", "0")
params.Add("$select", "id,title")
params.Add("$format", "json")

respBody := makeRequestWithHeadersAndQueryParams(t, testData.client, testData.url+"/consumptionBundles?", testData.headers, params)
Expand All @@ -480,6 +500,7 @@ func TestORDService(t *testing.T) {
params = url.Values{}
params.Add("$top", "10")
params.Add("$skip", fmt.Sprintf("%d", totalCount))
params.Add("$select", "id,title")
params.Add("$format", "json")

respBody = makeRequestWithHeadersAndQueryParams(t, testData.client, testData.url+"/consumptionBundles?", testData.headers, params)
Expand All @@ -490,13 +511,14 @@ func TestORDService(t *testing.T) {
totalCount := len(testData.appInput.Bundles[0].APIDefinitions)
params := urlpkg.Values{}

params.Add("$expand", "apis($top=10)")
params.Add("$select", "id,title")
params.Add("$expand", "apis($top=10;$select=id,title)")
params.Add("$format", "json")
respBody := makeRequestWithHeadersAndQueryParams(t, testData.client, testData.url+"/consumptionBundles?", testData.headers, params)
require.Equal(t, totalCount, len(gjson.Get(respBody, "value.0.apis").Array()))

expectedItemCount := 1
params.Set("$expand", fmt.Sprintf("apis($top=10;$skip=%d)", totalCount-expectedItemCount))
params.Set("$expand", fmt.Sprintf("apis($top=10;$skip=%d;$select=id,title)", totalCount-expectedItemCount))
respBody = makeRequestWithHeadersAndQueryParams(t, testData.client, testData.url+"/consumptionBundles?", testData.headers, params)
require.Equal(t, expectedItemCount, len(gjson.Get(respBody, "value").Array()))
})
Expand All @@ -505,13 +527,14 @@ func TestORDService(t *testing.T) {
totalCount := len(testData.appInput.Bundles[0].EventDefinitions)
params := urlpkg.Values{}

params.Add("$expand", "events($top=10)")
params.Add("$select", "id,title")
params.Add("$expand", "events($top=10;$select=id,title)")
params.Add("$format", "json")
respBody := makeRequestWithHeadersAndQueryParams(t, testData.client, testData.url+"/consumptionBundles?", testData.headers, params)
require.Equal(t, totalCount, len(gjson.Get(respBody, "value.0.events").Array()))

expectedItemCount := 1
params.Set("$expand", fmt.Sprintf("events($top=10;$skip=%d)", totalCount-expectedItemCount))
params.Set("$expand", fmt.Sprintf("events($top=10;$skip=%d;$select=id,title)", totalCount-expectedItemCount))
respBody = makeRequestWithHeadersAndQueryParams(t, testData.client, testData.url+"/consumptionBundles?", testData.headers, params)
require.Equal(t, expectedItemCount, len(gjson.Get(respBody, "value").Array()))
})
Expand All @@ -522,6 +545,7 @@ func TestORDService(t *testing.T) {

params := urlpkg.Values{}
params.Add("$filter", fmt.Sprintf("(title eq '%s')", bndlName))
params.Add("$select", "id,title")
params.Add("$format", "json")
serviceURL := testData.url + "/consumptionBundles?" + strings.ReplaceAll(params.Encode(), "+", "%20")
respBody := makeRequestWithHeaders(t, testData.client, serviceURL, testData.headers)
Expand All @@ -539,13 +563,14 @@ func TestORDService(t *testing.T) {

params := urlpkg.Values{}

params.Add("$expand", fmt.Sprintf("apis($filter=(title eq '%s'))", apiName))
params.Add("$expand", fmt.Sprintf("apis($filter=(title eq '%s');$select=id,title)", apiName))
params.Add("$select", "id,title")
params.Add("$format", "json")
serviceURL := testData.url + "/consumptionBundles?" + strings.ReplaceAll(params.Encode(), "+", "%20")
respBody := makeRequestWithHeaders(t, testData.client, serviceURL, testData.headers)
require.Equal(t, 1, len(gjson.Get(respBody, "value").Array()))

params.Set("$expand", fmt.Sprintf("apis($filter=(title ne '%s'))", apiName))
params.Set("$expand", fmt.Sprintf("apis($filter=(title ne '%s');$select=id,title)", apiName))
serviceURL = testData.url + "/consumptionBundles?" + strings.ReplaceAll(params.Encode(), "+", "%20")
respBody = makeRequestWithHeaders(t, testData.client, serviceURL, testData.headers)
require.Equal(t, totalCount-1, len(gjson.Get(respBody, "value.0.apis").Array()))
Expand All @@ -556,13 +581,14 @@ func TestORDService(t *testing.T) {
eventName := testData.appInput.Bundles[0].EventDefinitions[0].Name

params := urlpkg.Values{}
params.Add("$expand", fmt.Sprintf("events($filter=(title eq '%s'))", eventName))
params.Add("$expand", fmt.Sprintf("events($filter=(title eq '%s');$select=id,title)", eventName))
params.Add("$select", "id,title")
params.Add("$format", "json")
serviceURL := testData.url + "/consumptionBundles?" + strings.ReplaceAll(params.Encode(), "+", "%20")
respBody := makeRequestWithHeaders(t, testData.client, serviceURL, testData.headers)
require.Equal(t, 1, len(gjson.Get(respBody, "value").Array()))

params.Set("$expand", fmt.Sprintf("events($filter=(title ne '%s'))", eventName))
params.Set("$expand", fmt.Sprintf("events($filter=(title ne '%s');$select=id,title)", eventName))
serviceURL = testData.url + "/consumptionBundles?" + strings.ReplaceAll(params.Encode(), "+", "%20")
respBody = makeRequestWithHeaders(t, testData.client, serviceURL, testData.headers)
require.Equal(t, totalCount-1, len(gjson.Get(respBody, "value.0.events").Array()))
Expand All @@ -583,6 +609,7 @@ func TestORDService(t *testing.T) {
t.Run(fmt.Sprintf("Requesting projection of Bundle APIs for tenant %s returns them as expected", testData.msg), func(t *testing.T) {
params := urlpkg.Values{}

params.Add("$select", "id,title")
params.Add("$expand", "apis($select=title)")
params.Add("$format", "json")
respBody := makeRequestWithHeadersAndQueryParams(t, testData.client, testData.url+"/consumptionBundles?", testData.headers, params)
Expand All @@ -603,6 +630,7 @@ func TestORDService(t *testing.T) {
t.Run(fmt.Sprintf("Requesting projection of Bundle Events for tenant %s returns them as expected", testData.msg), func(t *testing.T) {
params := urlpkg.Values{}

params.Add("$select", "id,title")
params.Add("$expand", "events($select=title)")
params.Add("$format", "json")
respBody := makeRequestWithHeadersAndQueryParams(t, testData.client, testData.url+"/consumptionBundles?", testData.headers, params)
Expand All @@ -623,6 +651,7 @@ func TestORDService(t *testing.T) {
//Ordering:
t.Run(fmt.Sprintf("Requesting ordering of Bundles for tenant %s returns them as expected", testData.msg), func(t *testing.T) {
params := urlpkg.Values{}
params.Add("$select", "id,title,description")
params.Add("$orderby", "title asc,description desc")
params.Add("$format", "json")
serviceURL := testData.url + "/consumptionBundles?" + strings.ReplaceAll(params.Encode(), "+", "%20")
Expand All @@ -634,7 +663,8 @@ func TestORDService(t *testing.T) {

t.Run(fmt.Sprintf("Requesting ordering of Bundle APIs for tenant %s returns them as expected", testData.msg), func(t *testing.T) {
params := urlpkg.Values{}
params.Add("$expand", fmt.Sprintf("apis($orderby=%s)", "title asc,description desc"))
params.Add("$select", "id,title,description")
params.Add("$expand", fmt.Sprintf("apis($orderby=%s;$select=id,title,description)", "title asc,description desc"))
params.Add("$format", "json")
serviceURL := testData.url + "/consumptionBundles?" + strings.ReplaceAll(params.Encode(), "+", "%20")
respBody := makeRequestWithHeaders(t, testData.client, serviceURL, testData.headers)
Expand All @@ -655,8 +685,8 @@ func TestORDService(t *testing.T) {

t.Run(fmt.Sprintf("Requesting ordering of Bundle Events for tenant %s returns them as expected", testData.msg), func(t *testing.T) {
params := urlpkg.Values{}

params.Add("$expand", fmt.Sprintf("events($orderby=%s)", "title asc,description desc"))
params.Add("$select", "id,title,description")
params.Add("$expand", fmt.Sprintf("events($orderby=%s;$select=id,title,description)", "title asc,description desc"))
params.Add("$format", "json")
serviceURL := testData.url + "/consumptionBundles?" + strings.ReplaceAll(params.Encode(), "+", "%20")
respBody := makeRequestWithHeaders(t, testData.client, serviceURL, testData.headers)
Expand All @@ -679,6 +709,7 @@ func TestORDService(t *testing.T) {
t.Run("404 when request to ORD Service for api spec have another tenant header value", func(t *testing.T) {
params := urlpkg.Values{}

params.Add("$select", "id,resourceDefinitions")
params.Add("$format", "json")
respBody := makeRequestWithHeadersAndQueryParams(t, intSystemHttpClient, conf.ORDServiceURL+"/apis?", map[string][]string{tenantHeader: {defaultTestTenant}}, params)
require.Equal(t, len(appInput.Bundles[0].APIDefinitions), len(gjson.Get(respBody, "value").Array()))
Expand All @@ -695,6 +726,7 @@ func TestORDService(t *testing.T) {
t.Run("404 when request to ORD Service for event spec have another tenant header value", func(t *testing.T) {
params := urlpkg.Values{}

params.Add("$select", "id,resourceDefinitions")
params.Add("$format", "json")
respBody := makeRequestWithHeadersAndQueryParams(t, intSystemHttpClient, conf.ORDServiceURL+"/events?", map[string][]string{tenantHeader: {defaultTestTenant}}, params)
require.Equal(t, len(appInput.Bundles[0].EventDefinitions), len(gjson.Get(respBody, "value").Array()))
Expand Down
Loading

0 comments on commit f329eb6

Please sign in to comment.