From 8d27a10a2dd99b5fa08de7bf517457e2302a00f9 Mon Sep 17 00:00:00 2001 From: Arsalan Khan Date: Tue, 22 Oct 2024 18:20:28 +0200 Subject: [PATCH] adept broker acceptance to display binding configs --- .../default_policy-with-configuration.json | 98 +++++++++++++++++ .../policy-with-configuration-same-app.json | 100 ++++++++++++++++++ src/acceptance/broker/broker_test.go | 36 +++++-- 3 files changed, 224 insertions(+), 10 deletions(-) create mode 100644 src/acceptance/assets/file/policy/default_policy-with-configuration.json create mode 100644 src/acceptance/assets/file/policy/policy-with-configuration-same-app.json diff --git a/src/acceptance/assets/file/policy/default_policy-with-configuration.json b/src/acceptance/assets/file/policy/default_policy-with-configuration.json new file mode 100644 index 0000000000..e30e7c3ee2 --- /dev/null +++ b/src/acceptance/assets/file/policy/default_policy-with-configuration.json @@ -0,0 +1,98 @@ +{ + "configuration": { + "custom_metrics": { + "metric_submission_strategy": { + "allow_from": "same_app" + } + } + }, + "instance_min_count": 1, + "instance_max_count": 4, + "scaling_rules": [ + { + "metric_type": "memoryused", + "breach_duration_secs": 600, + "threshold": 30, + "operator": "<", + "cool_down_secs": 300, + "adjustment": "-1" + }, + { + "metric_type": "memoryused", + "breach_duration_secs": 600, + "threshold": 90, + "operator": ">=", + "cool_down_secs": 300, + "adjustment": "+1" + } + ], + "schedules": { + "timezone": "Asia/Shanghai", + "recurring_schedule": [ + { + "start_time": "10:00", + "end_time": "18:00", + "days_of_week": [ + 1, + 2, + 3 + ], + "instance_min_count": 1, + "instance_max_count": 10, + "initial_min_instance_count": 5 + }, + { + "start_date": "2099-06-27", + "end_date": "2099-07-23", + "start_time": "11:00", + "end_time": "19:30", + "days_of_month": [ + 5, + 15, + 25 + ], + "instance_min_count": 3, + "instance_max_count": 10, + "initial_min_instance_count": 5 + }, + { + "start_time": "10:00", + "end_time": "18:00", + "days_of_week": [ + 4, + 5, + 6 + ], + "instance_min_count": 1, + "instance_max_count": 10 + }, + { + "start_time": "11:00", + "end_time": "19:30", + "days_of_month": [ + 10, + 20, + 30 + ], + "instance_min_count": 1, + "instance_max_count": 10 + } + ], + "specific_date": [ + { + "start_date_time": "2099-06-02T10:00", + "end_date_time": "2099-06-15T13:59", + "instance_min_count": 1, + "instance_max_count": 4, + "initial_min_instance_count": 2 + }, + { + "start_date_time": "2099-01-04T20:00", + "end_date_time": "2099-02-19T23:15", + "instance_min_count": 2, + "instance_max_count": 5, + "initial_min_instance_count": 3 + } + ] + } +} diff --git a/src/acceptance/assets/file/policy/policy-with-configuration-same-app.json b/src/acceptance/assets/file/policy/policy-with-configuration-same-app.json new file mode 100644 index 0000000000..e4d492305d --- /dev/null +++ b/src/acceptance/assets/file/policy/policy-with-configuration-same-app.json @@ -0,0 +1,100 @@ +{ + "configuration": { + "custom_metrics": { + "metric_submission_strategy": { + "allow_from": "same_app" + } + } + }, + "instance_min_count": 1, + "instance_max_count": 4, + "scaling_rules": [ + { + "metric_type": "memoryused", + "breach_duration_secs": 600, + "threshold": 30, + "operator": "<", + "cool_down_secs": 300, + "adjustment": "-1" + }, + { + "metric_type": "memoryused", + "breach_duration_secs": 600, + "threshold": 90, + "operator": ">=", + "cool_down_secs": 300, + "adjustment": "+1" + } + ], + "schedules": { + "timezone": "Asia/Shanghai", + "recurring_schedule": [ + { + "start_time": "10:00", + "end_time": "18:00", + "days_of_week": [ + 1, + 2, + 3 + ], + "instance_min_count": 1, + "instance_max_count": 10, + "initial_min_instance_count": 5 + }, + { + "start_date": "2099-06-27", + "end_date": "2099-07-23", + "start_time": "11:00", + "end_time": "19:30", + "days_of_month": [ + 5, + 15, + 25 + ], + "instance_min_count": 3, + "instance_max_count": 10, + "initial_min_instance_count": 5 + }, + { + "start_time": "10:00", + "end_time": "18:00", + "days_of_week": [ + 4, + 5, + 6 + ], + "instance_min_count": 1, + "instance_max_count": 10 + }, + { + "start_time": "11:00", + "end_time": "19:30", + "days_of_month": [ + 10, + 20, + 30 + ], + "instance_min_count": 1, + "instance_max_count": 10 + } + ], + "specific_date": [ + { + "start_date_time": "2099-06-02T10:00", + "end_date_time": "2099-06-15T13:59", + "instance_min_count": 1, + "instance_max_count": 4, + "initial_min_instance_count": 2 + }, + { + "start_date_time": "2099-01-04T20:00", + "end_date_time": "2099-02-19T23:15", + "instance_min_count": 2, + "instance_max_count": 5, + "initial_min_instance_count": 3 + } + ] + } +} + + diff --git a/src/acceptance/broker/broker_test.go b/src/acceptance/broker/broker_test.go index 90865a78de..cd24771d21 100644 --- a/src/acceptance/broker/broker_test.go +++ b/src/acceptance/broker/broker_test.go @@ -95,14 +95,14 @@ var _ = Describe("AutoScaler Service Broker", func() { It("binds&unbinds with policy", func() { policyFile := "../assets/file/policy/all.json" - policy, err := os.ReadFile(policyFile) - Expect(err).NotTo(HaveOccurred()) - err = helpers.BindServiceToAppWithPolicy(cfg, appName, instance.name(), policyFile) + err := helpers.BindServiceToAppWithPolicy(cfg, appName, instance.name(), policyFile) + Expect(err).NotTo(HaveOccurred()) + expectedPolicyFile := "../assets/file/policy/policy-with-configuration-same-app.json" + expectedPolicyWithConfig, err := os.ReadFile(expectedPolicyFile) Expect(err).NotTo(HaveOccurred()) - bindingParameters := helpers.GetServiceCredentialBindingParameters(cfg, instance.name(), appName) - Expect(bindingParameters).Should(MatchJSON(policy)) + Expect(bindingParameters).Should(MatchJSON(expectedPolicyWithConfig)) instance.unbind(appName) }) @@ -142,10 +142,20 @@ var _ = Describe("AutoScaler Service Broker", func() { instance.unbind(appName) }) - It("bind&unbinds without policy", func() { + It("bind&unbinds without policy- gives only configuration", func() { helpers.BindServiceToApp(cfg, appName, instance.name()) bindingParameters := helpers.GetServiceCredentialBindingParameters(cfg, instance.name(), appName) - Expect(bindingParameters).Should(MatchJSON("{}")) + expectedJSON := `{ + "configuration": { + "custom_metrics": { + "metric_submission_strategy": { + "allow_from": "same_app" + } + } + } + }` + + Expect(bindingParameters).Should(MatchJSON(expectedJSON)) instance.unbind(appName) }) @@ -157,7 +167,7 @@ var _ = Describe("AutoScaler Service Broker", func() { Describe("allows setting default policies", func() { var instance serviceInstance var defaultPolicy []byte - var policy []byte + var expectedDefaultPolicyWithConfigsJSON []byte BeforeEach(func() { instance = createServiceWithParameters(cfg.ServicePlan, "../assets/file/policy/default_policy.json") @@ -173,7 +183,13 @@ var _ = Describe("AutoScaler Service Broker", func() { err = json.Unmarshal(defaultPolicy, &serviceParameters) Expect(err).NotTo(HaveOccurred()) - policy, err = json.Marshal(serviceParameters.DefaultPolicy) + expectedDefaultPolicyWithConfigsJSON, err = os.ReadFile("../assets/file/policy/default_policy-with-configuration.json") + Expect(err).NotTo(HaveOccurred()) + var serviceParametersWithConfigs = struct { + Configuration interface{} `json:"configuration"` + DefaultPolicy interface{} `json:"default_policy"` + }{} + err = json.Unmarshal(expectedDefaultPolicyWithConfigsJSON, &serviceParametersWithConfigs) Expect(err).NotTo(HaveOccurred()) }) @@ -186,7 +202,7 @@ var _ = Describe("AutoScaler Service Broker", func() { helpers.BindServiceToApp(cfg, appName, instance.name()) bindingParameters := helpers.GetServiceCredentialBindingParameters(cfg, instance.name(), appName) - Expect(bindingParameters).Should(MatchJSON(policy)) + Expect(bindingParameters).Should(MatchJSON(expectedDefaultPolicyWithConfigsJSON)) unbindService := cf.Cf("unbind-service", appName, instance.name()).Wait(cfg.DefaultTimeoutDuration()) Expect(unbindService).To(Exit(0), "failed unbinding service from app")