Skip to content

Commit

Permalink
Merge pull request #4727 from MartinForReal/shafan/fixclientv2
Browse files Browse the repository at this point in the history
track2 sdk: Fix: nil policy in percallpolicy option
  • Loading branch information
k8s-ci-robot authored Oct 8, 2023
2 parents de53be5 + af6f49e commit a9479c1
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 30 deletions.
4 changes: 3 additions & 1 deletion pkg/azclient/client-gen/generator/genclientfactory_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,9 @@ func NewClientFactory(config *ClientFactoryConfig, armConfig *ARMClientConfig, c
//add ratelimit policy
ratelimitOption = config.GetRateLimitConfig("{{.}}")
rateLimitPolicy = ratelimit.NewRateLimitPolicy(ratelimitOption)
options.ClientOptions.PerCallPolicies = append(options.ClientOptions.PerCallPolicies, rateLimitPolicy)
if rateLimitPolicy != nil {
options.ClientOptions.PerCallPolicies = append(options.ClientOptions.PerCallPolicies, rateLimitPolicy)
}
{{- end }}
{{$key}}, err := {{.PkgAlias}}.New(config.SubscriptionID, cred, options)
if err != nil {
Expand Down
68 changes: 51 additions & 17 deletions pkg/azclient/factory_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 10 additions & 12 deletions pkg/azclient/policy/retryonregionalendpoint/retry_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,12 @@ var _ = Describe("RetryEndpoint", func() {
StatusCode: http.StatusOK,
Body: http.NoBody,
}, nil
} else {
return &http.Response{
Request: req.Raw(),
StatusCode: http.StatusOK,
Body: streaming.NopCloser(strings.NewReader(`{"content":"content"}`)),
}, nil
}
return &http.Response{
Request: req.Raw(),
StatusCode: http.StatusOK,
Body: streaming.NopCloser(strings.NewReader(`{"content":"content"}`)),
}, nil
},
),
},
Expand All @@ -75,13 +74,12 @@ var _ = Describe("RetryEndpoint", func() {
ContentLength: 20,
Body: streaming.NopCloser(strings.NewReader(`{"error":{"code":"ResourceGroupNotFound"}}`)),
}, nil
} else {
return &http.Response{
Request: req.Raw(),
StatusCode: http.StatusOK,
Body: streaming.NopCloser(strings.NewReader(`{"content":"content"}`)),
}, nil
}
return &http.Response{
Request: req.Raw(),
StatusCode: http.StatusOK,
Body: streaming.NopCloser(strings.NewReader(`{"content":"content"}`)),
}, nil
},
),
},
Expand Down
1 change: 1 addition & 0 deletions pkg/azclient/policy/retryrepectthrottled/throttle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ var _ = Describe("Throttle", func() {
Expect(err).To(HaveOccurred())
throttlePolicy.RetryAfterWriter = time.Now().Add(-time.Second * 10)
req, err = runtime.NewRequest(context.Background(), http.MethodPut, "http://localhost:8080")
Expect(err).NotTo(HaveOccurred())
err = req.SetBody(streaming.NopCloser(strings.NewReader(`{"etag":"etag"}`)), "application/json")
Expect(err).NotTo(HaveOccurred())
_, err = pipeline.Do(req)
Expand Down

0 comments on commit a9479c1

Please sign in to comment.