Repository: Azure/azure-sdk-for-go
Pull request #23872 (2024-12-17 08:26:24)

Add error code in azfile error codes.go
<!--
Thank you for contributing to the Azure SDK for Go.

Please verify the following before submitting your PR, thank you!
-->

- [x] The purpose of this PR is explained in this or a referenced issue.
- [x] The PR does not update generated files.
   - These files are managed by the codegen framework at [Azure/autorest.go][].
- [x] Tests are included and/or updated for code changes.
- [x] Updates to module CHANGELOG.md are included.
- [x] MIT license headers are included in each file.

[Azure/autorest.go]: https://github.com/Azure/autorest.go



Patch:
diff --git a/eng/tools/generator/cmd/v2/automation/automationCmd.go b/eng/tools/generator/cmd/v2/automation/automationCmd.go
index 3984e5e2f1..41a657f2f8 100644
--- a/eng/tools/generator/cmd/v2/automation/automationCmd.go
+++ b/eng/tools/generator/cmd/v2/automation/automationCmd.go
@@ -108,6 +108,11 @@ func (ctx *automationContext) generate(input *pipeline.GenerateInput) (*pipeline
 	// typespec
 	// Generated by tsp only when tspconfig.yaml exists and has typespec-go option
 	for _, tspProjectFolder := range input.RelatedTypeSpecProjectFolder {
+		if !strings.Contains(tspProjectFolder, ".Management") {
+			log.Printf("Skip processing: %s, as it is not a management plane project", tspProjectFolder)
+			continue
+		}
+
 		tspconfigPath := filepath.Join(input.SpecFolder, tspProjectFolder, "tspconfig.yaml")
 		tsc, err := typespec.ParseTypeSpecConfig(tspconfigPath)
 		if err != nil {
@@ -182,6 +187,11 @@ func (ctx *automationContext) generate(input *pipeline.GenerateInput) (*pipeline
 	}
 
 	for _, readme := range input.RelatedReadmeMdFiles {
+		if !strings.Contains(readme, "resource-manager") {
+			log.Printf("Skip processing: %s, as it is not a management plane project", readme)
+			continue
+		}
+
 		log.Printf("Start to process autorest project: %s", readme)
 
 		sepStrs := strings.Split(readme, "/")
diff --git a/sdk/azcore/CHANGELOG.md b/sdk/azcore/CHANGELOG.md
index 7b9973b12e..f7713e06ce 100644
--- a/sdk/azcore/CHANGELOG.md
+++ b/sdk/azcore/CHANGELOG.md
@@ -5,6 +5,7 @@
 ### Features Added
 
 * Added field `OperationLocationResultPath` to `runtime.NewPollerOptions[T]` for LROs that use the `Operation-Location` pattern.
+* Support `encoding.TextMarshaler` and `encoding.TextUnmarshaler` interfaces in `arm.ResourceID`.
 
 ### Breaking Changes
 
diff --git a/sdk/azcore/arm/internal/resource/resource_identifier.go b/sdk/azcore/arm/internal/resource/resource_identifier.go
index 00f2d5a0ab..d9a4e36dcc 100644
--- a/sdk/azcore/arm/internal/resource/resource_identifier.go
+++ b/sdk/azcore/arm/internal/resource/resource_identifier.go
@@ -110,6 +110,21 @@ func (id *ResourceID) String() string {
 	return id.stringValue
 }
 
+// MarshalText returns a textual representation of the ResourceID
+func (id *ResourceID) MarshalText() ([]byte, error) {
+	return []byte(id.String()), nil
+}
+
+// UnmarshalText decodes the textual representation of a ResourceID
+func (id *ResourceID) UnmarshalText(text []byte) error {
+	newId, err := ParseResourceID(string(text))
+	if err != nil {
+		return err
+	}
+	*id = *newId
+	return nil
+}
+
 func newResourceID(parent *ResourceID, resourceTypeName string, resourceName string) *ResourceID {
 	id := &ResourceID{}
 	id.init(parent, chooseResourceType(resourceTypeName, parent), resourceName, true)
diff --git a/sdk/monitor/query/azmetrics/CHANGELOG.md b/sdk/monitor/query/azmetrics/CHANGELOG.md
index d72be8f985..2f0c1964c7 100644
--- a/sdk/monitor/query/azmetrics/CHANGELOG.md
+++ b/sdk/monitor/query/azmetrics/CHANGELOG.md
@@ -1,8 +1,9 @@
 # Release History
 
-## 1.1.1 (Unreleased)
+## 1.2.0 (Unreleased)
 
 ### Features Added
+* Added API Version support. Users can now change the default API Version by setting ClientOptions.APIVersion
 
 ### Breaking Changes
 
diff --git a/sdk/monitor/query/azmetrics/custom_client.go b/sdk/monitor/query/azmetrics/custom_client.go
index 80503cab81..c90287728c 100644
--- a/sdk/monitor/query/azmetrics/custom_client.go
+++ b/sdk/monitor/query/azmetrics/custom_client.go
@@ -42,7 +42,13 @@ func NewClient(endpoint string, credential azcore.TokenCredential, options *Clie
 	}
 
 	authPolicy := runtime.NewBearerTokenPolicy(credential, []string{c.Audience + "/.default"}, nil)
-	azcoreClient, err := azcore.NewClient(moduleName, version, runtime.PipelineOptions{PerRetry: []policy.Policy{authPolicy}}, &options.ClientOptions)
+	azcoreClient, err := azcore.NewClient(moduleName, version, runtime.PipelineOptions{
+		APIVersion: runtime.APIVersionOptions{
+			Location: runtime.APIVersionLocationQueryParam,
+			Name:     "api-version",
+		},
+		PerRetry: []policy.Policy{authPolicy},
+	}, &options.ClientOptions)
 	if err != nil {
 		return nil, err
 	}
diff --git a/sdk/monitor/query/azmetrics/version.go b/sdk/monitor/query/azmetrics/version.go
index 7a2b2c2d31..52ef17baa2 100644
--- a/sdk/monitor/query/azmetrics/version.go
+++ b/sdk/monitor/query/azmetrics/version.go
@@ -8,5 +8,5 @@ package azmetrics
 
 const (
 	moduleName = "github.com/Azure/azure-sdk-for-go/sdk/monitor/query/azmetrics"
-	version    = "v1.1.1"
+	version    = "v1.2.0"
 )
diff --git a/sdk/storage/azfile/assets.json b/sdk/storage/azfile/assets.json
index add86cbfe2..36bc40da6a 100644
--- a/sdk/storage/azfile/assets.json
+++ b/sdk/storage/azfile/assets.json
@@ -2,5 +2,5 @@
   "AssetsRepo": "Azure/azure-sdk-assets",
   "AssetsRepoPrefixPath": "go",
   "TagPrefix": "go/storage/azfile",
-  "Tag": "go/storage/azfile_c4deb17f89"
+  "Tag": "go/storage/azfile_5bfa72cc2c"
 }
diff --git a/sdk/storage/azfile/fileerror/error_codes.go b/sdk/storage/azfile/fileerror/error_codes.go
index c8c12f7691..43898d8123 100644
--- a/sdk/storage/azfile/fileerror/error_codes.go
+++ b/sdk/storage/azfile/fileerror/error_codes.go
@@ -91,6 +91,7 @@ const (
 	ShareDisabled                         Code = "ShareDisabled"
 	ShareHasSnapshots                     Code = "ShareHasSnapshots"
 	ShareNotFound                         Code = "ShareNotFound"
+	ShareSizeLimitReached                 Code = "ShareSizeLimitReached"
 	ShareSnapshotCountExceeded            Code = "ShareSnapshotCountExceeded"
 	ShareSnapshotInProgress               Code = "ShareSnapshotInProgress"
 	ShareSnapshotOperationNotSupported    Code = "ShareSnapshotOperationNotSupported"


Test patch:
diff --git a/sdk/azcore/arm/internal/resource/resource_identifier_test.go b/sdk/azcore/arm/internal/resource/resource_identifier_test.go
index aab7c66f3a..162bf533d7 100644
--- a/sdk/azcore/arm/internal/resource/resource_identifier_test.go
+++ b/sdk/azcore/arm/internal/resource/resource_identifier_test.go
@@ -6,7 +6,10 @@
 
 package resource
 
-import "testing"
+import (
+	"encoding"
+	"testing"
+)
 
 func TestParseResourceIdentifier(t *testing.T) {
 	testData := map[string]*ResourceID{
@@ -220,6 +223,26 @@ func TestParseResourceIdentifier(t *testing.T) {
 	}
 }
 
+// Ensure ResourceID implements these interfaces
+var _ encoding.TextMarshaler = (*ResourceID)(nil)
+var _ encoding.TextUnmarshaler = (*ResourceID)(nil)
+
+func TestMarshalResourceIdentifier(t *testing.T) {
+	resourceID := &ResourceID{}
+	input := []byte("/subscriptions/17fecd63-33d8-4e43-ac6f-0aafa111b38d/resourceGroups/myRg/providers/Microsoft.ApiManagement/service/myServiceName/subscriptions/mySubs")
+	err := resourceID.UnmarshalText(input)
+	if err != nil {
+		t.Fatalf("unexpected error: %+v", err)
+	}
+	output, err := resourceID.MarshalText()
+	if err != nil {
+		t.Fatalf("unexpected error: %+v", err)
+	}
+	if string(output) != string(input) {
+		t.Fatalf("resource id changed, got %v, expected %v", string(output), string(input))
+	}
+}
+
 func equals(left, right *ResourceID) bool {
 	if left != nil && right != nil {
 		if left.String() != right.String() {
diff --git a/sdk/monitor/query/azmetrics/client_test.go b/sdk/monitor/query/azmetrics/client_test.go
index 79c45130a8..e6db2b163d 100644
--- a/sdk/monitor/query/azmetrics/client_test.go
+++ b/sdk/monitor/query/azmetrics/client_test.go
@@ -8,10 +8,13 @@ package azmetrics_test
 
 import (
 	"context"
+	"net/http"
 	"testing"
 
 	"github.com/Azure/azure-sdk-for-go/sdk/azcore"
 	"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
+	"github.com/Azure/azure-sdk-for-go/sdk/internal/mock"
+	azcred "github.com/Azure/azure-sdk-for-go/sdk/internal/test/credential"
 	"github.com/Azure/azure-sdk-for-go/sdk/monitor/query/azmetrics"
 	"github.com/stretchr/testify/require"
 )
@@ -68,3 +71,31 @@ func TestQueryResources_Fail(t *testing.T) {
 
 	testSerde(t, &res)
 }
+
+func TestAPIVersion(t *testing.T) {
+	apiVersion := "2023-10-01"
+	var requireVersion = func(t *testing.T) func(req *http.Request) bool {
+		return func(r *http.Request) bool {
+			version := r.URL.Query().Get("api-version")
+			require.Equal(t, version, apiVersion)
+			return true
+		}
+	}
+	srv, close := mock.NewServer(mock.WithTransformAllRequestsToTestServerUrl())
+	defer close()
+	srv.AppendResponse(
+		mock.WithStatusCode(200),
+		mock.WithPredicate(requireVersion(t)),
+	)
+	srv.AppendResponse(mock.WithStatusCode(http.StatusInternalServerError))
+	opts := &azmetrics.ClientOptions{
+		ClientOptions: azcore.ClientOptions{
+			Transport:  srv,
+			APIVersion: apiVersion,
+		},
+	}
+	client, err := azmetrics.NewClient(endpoint, &azcred.Fake{}, opts)
+	require.NoError(t, err)
+	_, err = client.QueryResources(context.Background(), subscriptionID, "testing", []string{"test"}, azmetrics.ResourceIDList{}, nil)
+	require.NoError(t, err)
+}
diff --git a/sdk/storage/azfile/share/client_test.go b/sdk/storage/azfile/share/client_test.go
index 3043f3718b..230b86953e 100644
--- a/sdk/storage/azfile/share/client_test.go
+++ b/sdk/storage/azfile/share/client_test.go
@@ -298,6 +298,36 @@ func (s *ShareRecordedTestsSuite) TestShareCreateNilMetadata() {
 	_require.Len(response.Metadata, 0)
 }
 
+func (s *ShareRecordedTestsSuite) TestShareSizeLimitReached() {
+	_require := require.New(s.T())
+	testName := s.T().Name()
+
+	svcClient, err := testcommon.GetServiceClient(s.T(), testcommon.TestAccountDefault, nil)
+	_require.NoError(err)
+
+	shareName := testcommon.GenerateShareName(testName)
+	shareClient := svcClient.NewShareClient(shareName)
+
+	quotaInGB := int32(1) // Set a 1 GB quota
+	_, err = shareClient.Create(context.Background(), &service.CreateShareOptions{
+		Quota: &quotaInGB,
+	})
+	defer testcommon.DeleteShare(context.Background(), _require, shareClient)
+	_require.NoError(err)
+
+	// Attempt to exceed the share's quota
+	dirClient := shareClient.NewDirectoryClient("testdir")
+	_, err = dirClient.Create(context.Background(), nil)
+	_require.NoError(err)
+
+	fileClient := dirClient.NewFileClient("largefile")
+	fileSize := int64(2 * 1024 * 1024 * 1024) // 2 GB file to exceed 1 GB quota
+	_, err = fileClient.Create(context.Background(), fileSize, nil)
+	_require.Error(err)
+
+	testcommon.ValidateFileErrorCode(_require, err, fileerror.ShareSizeLimitReached)
+}
+
 func (s *ShareRecordedTestsSuite) TestShareCreateWithSnapshotVirtualDirectoryAccess() {
 	_require := require.New(s.T())
 	testName := s.T().Name()