Repository: kubernetes/kubernetes
File: pkg/scheduler/apis/config/validation/validation_pluginargs_test.go (Go)

Code before:
			expect: "name part must be no more than 63 characters",
		},
		{
			name: "IgnoredResourceGroups: name cannot be contain slash",
			args: config.NodeResourcesFitArgs{
				IgnoredResourceGroups: []string{"example.com/aa"},
				ScoringStrategy:       defaultScoringStrategy,
			},
			expect: "resource group name can't contain '/'",
		},
		{
			name:   "ScoringStrategy: field is required",
			args:   config.NodeResourcesFitArgs{},
			expect: "ScoringStrategy field is required",
		},
		{
			name: "ScoringStrategy: type is unsupported",
			args: config.NodeResourcesFitArgs{
				ScoringStrategy: &config.ScoringStrategy{
					Type: "Invalid",
				},
			},
			expect: `Unsupported value: "Invalid"`,
		},
		{
			name: "ScoringStrategy: requestedToCapacityRatio field is missing",
			args: config.NodeResourcesFitArgs{
				ScoringStrategy: &config.ScoringStrategy{
					Type: config.RequestedToCapacityRatio,
				},
			},
			expect: "must be specified when type is RequestedToCapacityRatio",
		},
	}

	for _, test := range argsTest {
		t.Run(test.name, func(t *testing.T) {
			if err := ValidateNodeResourcesFitArgs(nil, &test.args); err != nil && (!strings.Contains(err.Error(), test.expect)) {
				t.Errorf("case[%v]: error details do not include %v", test.name, err)
			}
		})
	}
}

func TestValidateLeastAllocatedScoringStrategy(t *testing.T) {
	tests := []struct {
		name      string
		resources []config.ResourceSpec
		wantErrs  field.ErrorList
	}{
		{

Review comment (bug):
I see the error validation for these tests is broken. If the validation returns success, we don't check that, even if we expected failure. Could you make a fix below like this:
```go
			err := ValidateNodeResourcesFitArgs(nil, &test.args)
			if err != nil {
				if test.expect == "" {
					t.Errorf("case[%v]: unexpected validation error %v", test.name, err)
				} else if !strings.Contains(err.Error(), test.expect) {
					t.Errorf("case[%v]: error details do not include %v", test.name, err)
				}
			} else if test.expect != "" {
				t.Errorf("case[%v]: expected validation error", test.name)
			}
```


Code after:
			expect: "name part must be no more than 63 characters",
		},
		{
			name: "IgnoredResourceGroups: name cannot be contain slash",
			args: config.NodeResourcesFitArgs{
				IgnoredResourceGroups: []string{"example.com/aa"},
				ScoringStrategy:       defaultScoringStrategy,
			},
			expect: "resource group name can't contain '/'",
		},
		{
			name:   "ScoringStrategy: field is required",
			args:   config.NodeResourcesFitArgs{},
			expect: "ScoringStrategy field is required",
		},
		{
			name: "ScoringStrategy: type is unsupported",
			args: config.NodeResourcesFitArgs{
				ScoringStrategy: &config.ScoringStrategy{
					Type: "Invalid",
				},
			},
			expect: `Unsupported value: "Invalid"`,
		},
		{
			name: "ScoringStrategy: requestedToCapacityRatio field is missing",
			args: config.NodeResourcesFitArgs{
				ScoringStrategy: &config.ScoringStrategy{
					Type: config.RequestedToCapacityRatio,
				},
			},
			expect: "must be specified when type is RequestedToCapacityRatio",
		},
	}

	for _, test := range argsTest {
		t.Run(test.name, func(t *testing.T) {
			err := ValidateNodeResourcesFitArgs(nil, &test.args)
			if err != nil {
				if test.expect == "" {
					t.Errorf("case[%v]: unexpected validation error %v", test.name, err)
				} else if !strings.Contains(err.Error(), test.expect) {
					t.Errorf("case[%v]: error details do not include %v", test.name, err)
				}
			} else if test.expect != "" {
				t.Errorf("case[%v]: expected validation error", test.name)
			}
		})
	}
}