Skip to content

Commit ff12634

Browse files
committed
some fixes
Signed-off-by: Britania Rodriguez Reyes <britaniar@microsoft.com>
1 parent 9c29de6 commit ff12634

5 files changed

Lines changed: 31 additions & 28 deletions

File tree

pkg/propertychecker/azure/checker_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ func TestCheckIfMeetSKUCapacityRequirement(t *testing.T) {
416416
errorSubstring: "capacity value cannot be zero for operator",
417417
},
418418
{
419-
name: "cases-insensitive request - unavailable SKU",
419+
name: "cases-insensitive request - available SKU",
420420
cluster: cluster,
421421
sku: "STANDARD_D2S_V3",
422422
targetCapacity: 1,
@@ -448,12 +448,11 @@ func TestCheckIfMeetSKUCapacityRequirement(t *testing.T) {
448448
if err == nil {
449449
t.Fatalf("CheckIfMeetSKUCapacityRequirement error () = nil, want error")
450450
} else if tt.errorSubstring != "" && !strings.Contains(err.Error(), tt.errorSubstring) {
451-
t.Errorf("CheckIfMeetSKUCapacityRequirement error () = %s, want %v", err, tt.errorSubstring)
451+
t.Fatalf("CheckIfMeetSKUCapacityRequirement error () = %s, want %v", err, tt.errorSubstring)
452452
}
453-
return
454453
}
455454

456-
if err != nil {
455+
if !tt.wantError && err != nil {
457456
t.Fatalf("CheckIfMeetSKUCapacityRequirement error () = %v, want nil", err)
458457
}
459458

pkg/scheduler/framework/plugins/clusteraffinity/filtering_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ import (
3636
"go.goms.io/fleet/pkg/propertyprovider/azure"
3737
"go.goms.io/fleet/pkg/scheduler/framework"
3838
"go.goms.io/fleet/pkg/utils/labels"
39-
computeUtils "go.goms.io/fleet/test/utils/azure/compute"
39+
testcompute "go.goms.io/fleet/test/utils/azure/compute"
4040
)
4141

4242
const (
@@ -775,6 +775,7 @@ func TestFilter(t *testing.T) {
775775
}
776776
}
777777

778+
// TestFilter_PropertyChecker tests the Filter extension point of the plugin with a property checker.
778779
func TestFilter_PropertyChecker(t *testing.T) {
779780
// This test ensures that the property checker is invoked correctly.
780781
testCases := []struct {
@@ -884,8 +885,8 @@ func TestFilter_PropertyChecker(t *testing.T) {
884885
for _, tc := range testCases {
885886
t.Run(tc.name, func(t *testing.T) {
886887
// Create mock server
887-
mockRequest := computeUtils.GenerateAttributeBasedVMSizeRecommenderRequest(tc.cluster.Labels[labels.AzureSubscriptionIDLabel], tc.cluster.Labels[labels.AzureLocationLabel], tc.vmSize, tc.targetCapacity)
888-
server := computeUtils.CreateMockAttributeBasedVMSizeRecommenderServer(t, mockRequest, computeUtils.MockAttributeBasedVMSizeRecommenderResponse, http.StatusOK)
888+
mockRequest := testcompute.GenerateAttributeBasedVMSizeRecommenderRequest(tc.cluster.Labels[labels.AzureSubscriptionIDLabel], tc.cluster.Labels[labels.AzureLocationLabel], tc.vmSize, tc.targetCapacity)
889+
server := testcompute.CreateMockAttributeBasedVMSizeRecommenderServer(t, mockRequest, testcompute.MockAttributeBasedVMSizeRecommenderResponse, http.StatusOK)
889890
defer server.Close()
890891

891892
client, err := compute.NewAttributeBasedVMSizeRecommenderClient(server.URL, http.DefaultClient)

pkg/scheduler/framework/plugins/clusteraffinity/plugin.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
"go.goms.io/fleet/pkg/scheduler/framework"
2626
)
2727

28-
// Plugin is the scheduler plugin that enforces the cluster affinity (if any) defined on a CRP.
28+
// Plugin is the scheduler plugin that enforces the cluster affinity (if any) defined on a RP/CRP.
2929
type Plugin struct {
3030
// The name of the plugin.
3131
name string

pkg/scheduler/framework/plugins/clusteraffinity/types_test.go

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,7 +1244,7 @@ func TestClusterRequirementMatches_WithPropertyChecker(t *testing.T) {
12441244
sku string
12451245
targetCapacity uint32
12461246
want bool
1247-
expectedToFail bool
1247+
wantError bool
12481248
}{
12491249
{
12501250
name: "invalid property name (not handled)",
@@ -1284,8 +1284,8 @@ func TestClusterRequirementMatches_WithPropertyChecker(t *testing.T) {
12841284
},
12851285
},
12861286
},
1287-
cluster: cluster,
1288-
expectedToFail: true,
1287+
cluster: cluster,
1288+
wantError: true,
12891289
},
12901290
{
12911291
name: "invalid value option",
@@ -1298,8 +1298,8 @@ func TestClusterRequirementMatches_WithPropertyChecker(t *testing.T) {
12981298
},
12991299
},
13001300
},
1301-
cluster: cluster,
1302-
expectedToFail: true,
1301+
cluster: cluster,
1302+
wantError: true,
13031303
},
13041304
{
13051305
name: "negative value option",
@@ -1312,8 +1312,8 @@ func TestClusterRequirementMatches_WithPropertyChecker(t *testing.T) {
13121312
},
13131313
},
13141314
},
1315-
cluster: cluster,
1316-
expectedToFail: true,
1315+
cluster: cluster,
1316+
wantError: true,
13171317
},
13181318
{
13191319
name: "non-integer value option",
@@ -1326,8 +1326,8 @@ func TestClusterRequirementMatches_WithPropertyChecker(t *testing.T) {
13261326
},
13271327
},
13281328
},
1329-
cluster: cluster,
1330-
expectedToFail: true,
1329+
cluster: cluster,
1330+
wantError: true,
13311331
},
13321332
{
13331333
name: "invalid operator",
@@ -1340,8 +1340,8 @@ func TestClusterRequirementMatches_WithPropertyChecker(t *testing.T) {
13401340
},
13411341
},
13421342
},
1343-
cluster: cluster,
1344-
expectedToFail: true,
1343+
cluster: cluster,
1344+
wantError: true,
13451345
},
13461346
{
13471347
name: "op >, matched (min limit)",
@@ -1428,14 +1428,13 @@ func TestClusterRequirementMatches_WithPropertyChecker(t *testing.T) {
14281428
PropertyChecker: azure.NewPropertyChecker(*client),
14291429
}
14301430
matches, err := req.Matches(tc.cluster)
1431-
if tc.expectedToFail {
1431+
if tc.wantError {
14321432
if err == nil {
1433-
t.Errorf("Matches() (With Property Checker), want error, got nil")
1433+
t.Fatalf("Matches() (With Property Checker), want error, got nil")
14341434
}
1435-
return
14361435
}
14371436

1438-
if err != nil || matches != tc.want {
1437+
if (!tc.wantError && err != nil) || matches != tc.want {
14391438
t.Errorf("Matches() (With Property Checker) = %v, %v, want %v, nil", matches, err, tc.want)
14401439
}
14411440
})

test/utils/azure/compute/compute.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
//
2+
//Copyright (c) Microsoft Corporation.
3+
//Licensed under the MIT license.
4+
15
// compute package provides utilities for testing Azure Compute services.
26
package 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.
5862
func 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

Comments
 (0)