@@ -29,6 +29,7 @@ type ClientGenConfig struct {
29
29
Expand bool `marker:"expand,optional"`
30
30
RateLimitKey string `marker:"rateLimitKey,optional"`
31
31
CrossSubFactory bool `marker:"crossSubFactory,optional"`
32
+ Etag bool `marker:"etag,optional"`
32
33
}
33
34
34
35
var ClientTemplate = template .Must (template .New ("object-scaffolding-client-struct" ).Parse (`
@@ -45,7 +46,9 @@ func New({{if not .OutOfSubscriptionScope}}subscriptionID string, {{end}}credent
45
46
options = utils.GetDefaultOption()
46
47
}
47
48
tr := options.TracingProvider.NewTracer(utils.ModuleName, utils.ModuleVersion)
48
-
49
+ {{with .Etag}}
50
+ options.ClientOptions.PerCallPolicies = append(options.ClientOptions.PerCallPolicies, utils.FuncPolicyWrapper(etag.AppendEtag))
51
+ {{- end}}
49
52
client, err := {{.PackageAlias}}.New{{.ClientName}}({{if not .OutOfSubscriptionScope}}subscriptionID,{{end}} credential, options)
50
53
if err != nil {
51
54
return nil, err
@@ -294,8 +297,8 @@ var _ = ginkgo.Describe("{{.ClientName}}",ginkgo.Ordered, func() {
294
297
}
295
298
296
299
{{if $HasCreateOrUpdate}}
297
- ginkgo.When("creation requests are raised", func() {
298
- ginkgo.It("should not return error", func(ctx context.Context) {
300
+ ginkgo.When("creation requests are raised", func() {
301
+ ginkgo.It("should not return error", func(ctx context.Context) {
299
302
newResource, err := realClient.CreateOrUpdate(ctx, resourceGroupName,{{with .SubResource}}parentResourceName,{{end}} resourceName, *newResource)
300
303
gomega.Expect(err).NotTo(gomega.HaveOccurred())
301
304
gomega.Expect(newResource).NotTo(gomega.BeNil())
@@ -304,51 +307,58 @@ ginkgo.It("should not return error", func(ctx context.Context) {
304
307
})
305
308
{{end -}}
306
309
{{if $HasGet}}
307
- ginkgo.When("get requests are raised", func() {
308
- ginkgo.It("should not return error", func(ctx context.Context) {
310
+ ginkgo.When("get requests are raised", func() {
311
+ ginkgo.It("should not return error", func(ctx context.Context) {
309
312
newResource, err := realClient.Get(ctx, resourceGroupName,{{with .SubResource}}parentResourceName,{{end}} resourceName{{if .Expand}}, nil{{end}})
310
313
gomega.Expect(err).NotTo(gomega.HaveOccurred())
311
314
gomega.Expect(newResource).NotTo(gomega.BeNil())
312
315
})
313
316
})
314
- ginkgo.When("invalid get requests are raised", func() {
315
- ginkgo.It("should return 404 error", func(ctx context.Context) {
317
+ ginkgo.When("invalid get requests are raised", func() {
318
+ ginkgo.It("should return 404 error", func(ctx context.Context) {
316
319
newResource, err := realClient.Get(ctx, resourceGroupName,{{with .SubResource}}parentResourceName,{{end}} resourceName+"notfound"{{if .Expand}}, nil{{end}})
317
320
gomega.Expect(err).To(gomega.HaveOccurred())
318
321
gomega.Expect(newResource).To(gomega.BeNil())
319
322
})
320
323
})
321
324
{{end -}}
322
325
{{if $HasCreateOrUpdate}}
323
- ginkgo.When("update requests are raised", func() {
324
- ginkgo.It("should not return error", func(ctx context.Context) {
326
+ ginkgo.When("update requests are raised", func() {
327
+ ginkgo.It("should not return error", func(ctx context.Context) {
325
328
newResource, err := realClient.CreateOrUpdate(ctx, resourceGroupName,{{with .SubResource}}parentResourceName,{{end}} resourceName, *newResource)
326
329
gomega.Expect(err).NotTo(gomega.HaveOccurred())
327
330
gomega.Expect(newResource).NotTo(gomega.BeNil())
328
331
})
332
+ {{if .Etag}}
333
+ ginkgo.It("should return error", func(ctx context.Context) {
334
+ newResource.Etag = to.Ptr("invalid")
335
+ _, err := realClient.CreateOrUpdate(ctx, resourceGroupName,{{with .SubResource}}parentResourceName,{{end}} resourceName, *newResource)
336
+ gomega.Expect(err).To(gomega.HaveOccurred())
337
+ })
338
+ {{end -}}
329
339
})
330
340
{{end -}}
331
341
{{if or $HasListByRG $HasList}}
332
- ginkgo.When("list requests are raised", func() {
333
- ginkgo.It("should not return error", func(ctx context.Context) {
342
+ ginkgo.When("list requests are raised", func() {
343
+ ginkgo.It("should not return error", func(ctx context.Context) {
334
344
resourceList, err := realClient.List(ctx, resourceGroupName,{{with .SubResource}}parentResourceName{{end}})
335
345
gomega.Expect(err).NotTo(gomega.HaveOccurred())
336
346
gomega.Expect(resourceList).NotTo(gomega.BeNil())
337
347
gomega.Expect(len(resourceList)).To(gomega.Equal(1))
338
348
gomega.Expect(*resourceList[0].Name).To(gomega.Equal(resourceName))
339
349
})
340
350
})
341
- ginkgo.When("invalid list requests are raised", func() {
342
- ginkgo.It("should return error", func(ctx context.Context) {
351
+ ginkgo.When("invalid list requests are raised", func() {
352
+ ginkgo.It("should return error", func(ctx context.Context) {
343
353
resourceList, err := realClient.List(ctx, resourceGroupName+"notfound",{{with .SubResource}}parentResourceName{{end}})
344
354
gomega.Expect(err).To(gomega.HaveOccurred())
345
355
gomega.Expect(resourceList).To(gomega.BeNil())
346
356
})
347
357
})
348
358
{{end -}}
349
359
{{if $HasDelete}}
350
- ginkgo.When("deletion requests are raised", func() {
351
- ginkgo.It("should not return error", func(ctx context.Context) {
360
+ ginkgo.When("deletion requests are raised", func() {
361
+ ginkgo.It("should not return error", func(ctx context.Context) {
352
362
err = realClient.Delete(ctx, resourceGroupName,{{with .SubResource}}parentResourceName,{{end}} resourceName)
353
363
gomega.Expect(err).NotTo(gomega.HaveOccurred())
354
364
})
0 commit comments