Skip to content

Commit

Permalink
azfile: STG 91 code generation (#22134)
Browse files Browse the repository at this point in the history
  • Loading branch information
souravgupta-msft authored Dec 14, 2023
1 parent f94bde2 commit d6fa08e
Show file tree
Hide file tree
Showing 9 changed files with 180 additions and 96 deletions.
37 changes: 37 additions & 0 deletions sdk/storage/azfile/file/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/Azure/azure-sdk-for-go/sdk/storage/azblob"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/file"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/fileerror"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/internal/generated"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/internal/shared"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/internal/testcommon"
"github.com/Azure/azure-sdk-for-go/sdk/storage/azfile/lease"
Expand Down Expand Up @@ -4340,4 +4341,40 @@ func (f *FileUnrecordedTestsSuite) TestFileUploadRangeFromURLNow() {
_require.NotEqualValues(*uResp.FileLastWriteTime, *cResp.FileLastWriteTime)
}

type serviceVersionTest struct{}

// newServiceVersionTestPolicy returns a policy that checks the x-ms-version header
func newServiceVersionTestPolicy() policy.Policy {
return &serviceVersionTest{}
}

func (m serviceVersionTest) Do(req *policy.Request) (*http.Response, error) {
const versionHeader = "x-ms-version"
currentVersion := map[string][]string(req.Raw().Header)[versionHeader]
if currentVersion[0] != generated.ServiceVersion {
return nil, fmt.Errorf(currentVersion[0] + " service version doesn't match expected version: " + generated.ServiceVersion)
}

return &http.Response{
Request: req.Raw(),
Status: "Created",
StatusCode: http.StatusCreated,
Header: http.Header{},
Body: http.NoBody,
}, nil
}

func TestServiceVersion(t *testing.T) {
client, err := file.NewClientWithNoCredential("https://fake/file/testpath", &file.ClientOptions{
ClientOptions: policy.ClientOptions{
PerCallPolicies: []policy.Policy{newServiceVersionTestPolicy()},
},
})
require.NoError(t, err)
require.NotNil(t, client)

_, err = client.Create(context.Background(), 1024, nil)
require.NoError(t, err)
}

// TODO: Add tests for retry header options
18 changes: 17 additions & 1 deletion sdk/storage/azfile/internal/generated/autorest.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ go: true
clear-output-folder: false
version: "^3.0.0"
license-header: MICROSOFT_MIT_NO_VERSION
input-file: "https://raw.githubusercontent.com/Azure/azure-rest-api-specs/7dcd41cd28d46eb256bac034760a7e2f0a036238/specification/storage/data-plane/Microsoft.FileStorage/preview/2022-11-02/file.json"
input-file: "https://raw.githubusercontent.com/Azure/azure-rest-api-specs/4bafbf3ab1532e390ad5757433679e9ebb5cbf38/specification/storage/data-plane/Microsoft.FileStorage/preview/2023-08-03/file.json"
credential-scope: "https://storage.azure.com/.default"
output-folder: ../generated
file-prefix: "zz_"
Expand All @@ -22,6 +22,22 @@ export-clients: true
use: "@autorest/[email protected]"
```
### Updating service version to 2023-11-03
```yaml
directive:
- from:
- zz_directory_client.go
- zz_file_client.go
- zz_share_client.go
- zz_service_client.go
where: $
transform: >-
return $.
replaceAll(`[]string{"2023-08-03"}`, `[]string{ServiceVersion}`).
replaceAll(`2023-08-03`, `2023-11-03`);
```
### Don't include share name, directory, or file name in path - we have direct URIs
``` yaml
Expand Down
9 changes: 9 additions & 0 deletions sdk/storage/azfile/internal/generated/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//go:build go1.18
// +build go1.18

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for license information.

package generated

const ServiceVersion = "2023-11-03"
18 changes: 18 additions & 0 deletions sdk/storage/azfile/internal/generated/zz_constants.go

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

36 changes: 18 additions & 18 deletions sdk/storage/azfile/internal/generated/zz_directory_client.go

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

Loading

0 comments on commit d6fa08e

Please sign in to comment.