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

Commit

Permalink
Fix TestRuntimeContextSubscriptionFlows e2e test assertions (#2499)
Browse files Browse the repository at this point in the history
* Double maintaining of hotfix.

* Update values.yaml

* Fix comment.

* Fix comment.

* Address PR comment
  • Loading branch information
la4ezar authored Jul 21, 2022
1 parent 016407b commit 34b206c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
2 changes: 1 addition & 1 deletion chart/compass/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ global:
version: "PR-68"
e2e_tests:
dir:
version: "PR-2495"
version: "PR-2499"
isLocalEnv: false
isForTesting: false
enableInternalCommunicationPolicies: true
Expand Down
34 changes: 17 additions & 17 deletions tests/director/tests/runtime_contexts_api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,9 @@ func TestRuntimeContextSubscriptionFlows(stdT *testing.T) {
t := testingx.NewT(stdT)
t.Run("Runtime Contexts subscription flows", func(t *testing.T) {
ctx := context.Background()
subscriptionProviderSubaccountID := conf.TestProviderSubaccountID // the parent is testDefaultTenant
subscriptionConsumerAccountID := conf.TestConsumerAccountID // the parent is ApplicationsForRuntimeTenantName
subscriptionConsumerSubaccountID := conf.TestConsumerSubaccountID
subscriptionProviderSubaccountID := conf.TestProviderSubaccountID // in local set up the parent is testDefaultTenant
subscriptionConsumerAccountID := conf.TestConsumerAccountID
subscriptionConsumerSubaccountID := conf.TestConsumerSubaccountID // in local set up the parent is ApplicationsForRuntimeTenantName
subscriptionConsumerTenantID := conf.TestConsumerTenantID

// Prepare provider external client certificate and secret and Build graphql director client configured with certificate
Expand Down Expand Up @@ -239,30 +239,28 @@ func TestRuntimeContextSubscriptionFlows(stdT *testing.T) {
t.Logf("Successfully created subscription between consumer with subaccount id: %q and tenant id: %q, and provider with name: %q, id: %q and subaccount id: %q", subscriptionConsumerSubaccountID, subscriptionConsumerTenantID, providerRuntime.Name, providerRuntime.ID, subscriptionProviderSubaccountID)

t.Log("Assert provider runtime is visible in the consumer's subaccount after successful subscription")
consumerSubaccountRuntimes := fixtures.ListRuntimes(t, ctx, certSecuredGraphQLClient, subscriptionConsumerSubaccountID)
require.Len(t, consumerSubaccountRuntimes.Data, 1)
require.Equal(t, consumerSubaccountRuntimes.Data[0].ID, providerRuntime.ID)
consumerSubaccountRuntime := fixtures.GetRuntime(t, ctx, certSecuredGraphQLClient, subscriptionConsumerSubaccountID, providerRuntime.ID)
require.Equal(t, providerRuntime.ID, consumerSubaccountRuntime.ID)

t.Log("Assert subscription provider application name label of the provider runtime exists and it is the correct one")
subProviderAppNameValue, ok := consumerSubaccountRuntimes.Data[0].Labels[conf.RuntimeTypeLabelKey].(string)
subProviderAppNameValue, ok := consumerSubaccountRuntime.Labels[conf.RuntimeTypeLabelKey].(string)
require.True(t, ok)
require.Equal(t, conf.SubscriptionProviderAppNameValue, subProviderAppNameValue)

t.Log("Assert there is a runtime context(subscription) as part of the provider runtime")
require.Len(t, consumerSubaccountRuntimes.Data[0].RuntimeContexts.Data, 1)
require.Equal(t, conf.SubscriptionLabelKey, consumerSubaccountRuntimes.Data[0].RuntimeContexts.Data[0].Key)
require.Equal(t, subscriptionConsumerTenantID, consumerSubaccountRuntimes.Data[0].RuntimeContexts.Data[0].Value)
require.Len(t, consumerSubaccountRuntime.RuntimeContexts.Data, 1)
require.Equal(t, conf.SubscriptionLabelKey, consumerSubaccountRuntime.RuntimeContexts.Data[0].Key)
require.Equal(t, subscriptionConsumerTenantID, consumerSubaccountRuntime.RuntimeContexts.Data[0].Value)

t.Log("Assert the runtime context has label containing consumer subaccount ID")
consumerSubaccountFromRtmCtxLabel, ok := consumerSubaccountRuntimes.Data[0].RuntimeContexts.Data[0].Labels[conf.ConsumerSubaccountLabelKey].(string)
consumerSubaccountFromRtmCtxLabel, ok := consumerSubaccountRuntime.RuntimeContexts.Data[0].Labels[conf.ConsumerSubaccountLabelKey].(string)
require.True(t, ok)
require.Equal(t, subscriptionConsumerSubaccountID, consumerSubaccountFromRtmCtxLabel)

t.Log("Assert provider runtime is visible in the consumer's account after successful subscription")
consumerAccountRuntimes := fixtures.ListRuntimes(t, ctx, certSecuredGraphQLClient, subscriptionConsumerAccountID)
require.Len(t, consumerAccountRuntimes.Data, 1)
require.Equal(t, consumerAccountRuntimes.Data[0].ID, providerRuntime.ID)
require.Len(t, consumerSubaccountRuntimes.Data[0].RuntimeContexts.Data, 1)
consumerAccountRuntime := fixtures.GetRuntime(t, ctx, certSecuredGraphQLClient, subscriptionConsumerAccountID, providerRuntime.ID)
require.Equal(t, providerRuntime.ID, consumerAccountRuntime.ID)
require.Len(t, consumerSubaccountRuntime.RuntimeContexts.Data, 1)

t.Log("Assert the consumer cannot update the provider runtime(owner false check)")
consumerRuntimeUpdateInput := fixRuntimeUpdateInput("consumerUpdatedRuntime")
Expand All @@ -271,13 +269,15 @@ func TestRuntimeContextSubscriptionFlows(stdT *testing.T) {
require.Error(t, err)
require.Contains(t, err.Error(), "Owner access is needed for resource modification")

t.Log("Assert the consumer cannot delete the provider runtime(owner false check)")
t.Log("Assert the consumer cannot delete the provider runtime(cleanup of self-registered runtime failure)")
deleteRuntimeReq := fixtures.FixUnregisterRuntimeRequest(providerRuntime.ID)
rtmExt := graphql.RuntimeExt{}
err = testctx.Tc.RunOperationWithCustomTenant(ctx, certSecuredGraphQLClient, subscriptionConsumerSubaccountID, deleteRuntimeReq, &rtmExt)
require.Empty(t, rtmExt)
require.Error(t, err)
require.Contains(t, err.Error(), "Owner access is needed for resource modification")
// TODO:: Adjust external-services-mock to handle self-registration cleanup properly
// If we call with tenant that have owner=false, we shouldn't be able to cleanup the self-registered runtime
//require.Contains(t, err.Error(), "An error occurred during cleanup of self-registered runtime")

subscription.BuildAndExecuteUnsubscribeRequest(t, providerRuntime.ID, providerRuntime.Name, httpClient, conf.SubscriptionConfig.URL, apiPath, subscriptionToken, conf.SubscriptionConfig.PropagatedProviderSubaccountHeader, subscriptionConsumerSubaccountID, subscriptionConsumerTenantID, subscriptionProviderSubaccountID)

Expand Down

0 comments on commit 34b206c

Please sign in to comment.