1+ //
2+ //Copyright (c) Microsoft Corporation.
3+ //Licensed under the MIT license.
4+
15// compute package provides utilities for testing Azure Compute services.
26package compute
37
@@ -57,27 +61,27 @@ func GenerateAttributeBasedVMSizeRecommenderRequest(subscriptionID, location, sk
5761// CreateMockAttributeBasedVMSizeRecommenderServer is a helper function to create a mock server with a generated response.
5862func CreateMockAttributeBasedVMSizeRecommenderServer (t * testing.T , request * computev1.GenerateAttributeBasedRecommendationsRequest , response string , httpStatusCode int ) * httptest.Server {
5963 return httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
60- // Verify request method
64+ // Verify request method.
6165 if r .Method != http .MethodPost {
6266 t .Errorf ("got %s, want POST request" , r .Method )
6367 }
6468
65- // Verify headers
69+ // Verify headers.
6670 if r .Header .Get (httputil .HeaderContentTypeKey ) != httputil .HeaderContentTypeJSON {
6771 t .Errorf ("got %s, want Content-Type: %s" , r .Header .Get (httputil .HeaderContentTypeKey ), httputil .HeaderContentTypeJSON )
6872 }
6973 if r .Header .Get (httputil .HeaderAcceptKey ) != httputil .HeaderContentTypeJSON {
7074 t .Errorf ("got %s, want Accept: %s" , r .Header .Get (httputil .HeaderAcceptKey ), httputil .HeaderContentTypeJSON )
7175 }
7276
73- // Verify URL path if request is not nil
77+ // Verify URL path if request is not nil.
7478 if request != nil && request .SubscriptionId != "" && request .Location != "" {
7579 wantPath := fmt .Sprintf ("/subscriptions/%s/providers/Microsoft.Compute/locations/%s/vmSizeRecommendations/vmAttributeBased/generate" , request .SubscriptionId , request .Location )
7680 if r .URL .Path != wantPath {
7781 t .Errorf ("got %s, want path %s" , r .URL .Path , wantPath )
7882 }
7983
80- // Verify request body using protojson for proper proto3 oneof support
84+ // Verify request body using protojson for proper proto3 oneof support.
8185 body , err := io .ReadAll (r .Body )
8286 if err != nil {
8387 t .Fatalf ("failed to read request body: %v" , err )
@@ -94,7 +98,7 @@ func CreateMockAttributeBasedVMSizeRecommenderServer(t *testing.T, request *comp
9498 }
9599 }
96100
97- // Write mock response
101+ // Write mock response.
98102 w .WriteHeader (httpStatusCode )
99103 if _ , err := w .Write ([]byte (response )); err != nil {
100104 t .Fatalf ("failed to write response: %v" , err )
0 commit comments