@@ -29,7 +29,7 @@ var _ = Describe("API Helper Test", func() {
2929 err error
3030 apiServer * ghttp.Server
3131 apihelper * APIHelper
32- fakePolicy ScalingPolicy = ScalingPolicy {
32+ fakePolicy = ScalingPolicy {
3333 InstanceMin : 1 ,
3434 InstanceMax : 2 ,
3535 ScalingRules : []* ScalingRule {
@@ -44,6 +44,56 @@ var _ = Describe("API Helper Test", func() {
4444 },
4545 },
4646 }
47+ fakePolicyWithConfiguration = ScalingPolicy {
48+ InstanceMin : 1 ,
49+ InstanceMax : 2 ,
50+ ScalingRules : []* ScalingRule {
51+ {
52+ MetricType : "memoryused" ,
53+ StatWindowSeconds : 300 ,
54+ BreachDurationSeconds : 600 ,
55+ Threshold : 30 ,
56+ Operator : "<=" ,
57+ CoolDownSeconds : 300 ,
58+ Adjustment : "-1" ,
59+ },
60+ },
61+ Configuration : & Configuration {
62+ CustomMetrics : struct {
63+ MetricSubmissionStrategy struct {
64+ AllowFrom string `json:"allow_from"`
65+ } `json:"metric_submission_strategy"`
66+ }{
67+ MetricSubmissionStrategy : struct {
68+ AllowFrom string `json:"allow_from"`
69+ }{
70+ AllowFrom : "bound_app" ,
71+ },
72+ },
73+ },
74+ }
75+ expectedPolicyWithConfigurationJSON = `{
76+ "instance_min_count": 1,
77+ "instance_max_count": 2,
78+ "scaling_rules": [
79+ {
80+ "metric_type": "memoryused",
81+ "stat_window_secs": 300,
82+ "breach_duration_secs": 600,
83+ "threshold": 30,
84+ "operator": "<=",
85+ "cool_down_secs": 300,
86+ "adjustment": "-1"
87+ }
88+ ],
89+ "configuration": {
90+ "custom_metrics": {
91+ "metric_submission_strategy": {
92+ "allow_from": "bound_app"
93+ }
94+ }
95+ }
96+ }`
4797 )
4898
4999 BeforeEach (func () {
@@ -174,7 +224,7 @@ var _ = Describe("API Helper Test", func() {
174224 })
175225
176226 Context ("Get policy" , func () {
177- var urlpath string = "/v1/apps/" + fakeAppId + "/policy"
227+ var urlpath = "/v1/apps/" + fakeAppId + "/policy"
178228
179229 Context ("Succeed with valid auth token" , func () {
180230 BeforeEach (func () {
@@ -186,12 +236,12 @@ var _ = Describe("API Helper Test", func() {
186236 )
187237 })
188238
189- It ("succeed" , func () {
239+ It ("succeed with policy only " , func () {
190240 response , err := apihelper .GetPolicy ()
191241 Expect (err ).NotTo (HaveOccurred ())
192242
193243 var actualPolicy ScalingPolicy
194- _ = json .Unmarshal ([] byte ( response ) , & actualPolicy )
244+ _ = json .Unmarshal (response , & actualPolicy )
195245 Expect (actualPolicy ).To (MatchFields (IgnoreExtras , Fields {
196246 "InstanceMin" : BeNumerically ("==" , fakePolicy .InstanceMin ),
197247 "InstanceMax" : BeNumerically ("==" , fakePolicy .InstanceMax ),
@@ -207,6 +257,19 @@ var _ = Describe("API Helper Test", func() {
207257 "Adjustment" : Equal (fakePolicy .ScalingRules [0 ].Adjustment ),
208258 }))
209259 })
260+ It ("succeed with policy and configuration" , func () {
261+ apiServer .RouteToHandler ("GET" , urlpath ,
262+ ghttp .CombineHandlers (
263+ ghttp .RespondWithJSONEncoded (http .StatusOK , & fakePolicyWithConfiguration ),
264+ ghttp .VerifyHeaderKV ("Authorization" , fakeAccessToken ),
265+ ),
266+ )
267+ response , err := apihelper .GetPolicy ()
268+ Expect (err ).NotTo (HaveOccurred ())
269+
270+ Expect (response ).To (MatchJSON (expectedPolicyWithConfigurationJSON ))
271+
272+ })
210273 })
211274
212275 Context ("Unauthorized Access" , func () {
@@ -748,7 +811,7 @@ var _ = Describe("API Helper Test", func() {
748811
749812 })
750813
751- Context ("Get Histrory " , func () {
814+ Context ("Get History " , func () {
752815 var urlpath = "/v1/apps/" + fakeAppId + "/scaling_histories"
753816 var now int64
754817 var histories , reversedHistories []* AppScalingHistory
0 commit comments