Skip to content
This repository was archived by the owner on Jan 29, 2025. It is now read-only.

Commit 3e592a2

Browse files
killianmuldoonkillianmuldoon
killianmuldoon
authored andcommitted
Fix staticheck errors
Linter staticcheck is added through golint-ci. This update fixes the issues identified by the linter. Some of these changes have minor impact on control flow especially in tests.
1 parent ac2bb45 commit 3e592a2

File tree

6 files changed

+12
-15
lines changed

6 files changed

+12
-15
lines changed

pkg/cache/autoupdating_test.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -177,11 +177,13 @@ func TestNodeMetricsCache_WriteMetric(t *testing.T) {
177177
for _, tt := range tests {
178178
t.Run(tt.name, func(t *testing.T) {
179179
err := tt.n.WriteMetric(tt.args.metricName, nil)
180-
if err == nil && tt.errorExpected {
180+
if err != nil && !tt.errorExpected {
181+
t.Log(err)
181182
t.Fail()
182183
}
183184
_, err = tt.n.ReadMetric(tt.queriedMetric)
184185
if err == nil && tt.errorExpected {
186+
t.Log(err)
185187
t.Fail()
186188
}
187189
})

pkg/metrics/client_test.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func dummyRestClientConfig() *restclient.Config {
3939
fallbackReader := bytes.NewBuffer([]byte{})
4040
clientConfig := clientcmd.NewInteractiveDeferredLoadingClientConfig(loadingRules, overrides, fallbackReader)
4141
restConfig, err := clientConfig.ClientConfig()
42-
if err == nil {
42+
if err != nil {
4343
log.Fatalf("Can't create dummy rest client config %v ", err)
4444
}
4545
return restConfig
@@ -98,7 +98,7 @@ func Test_customMetricsClient_GetNodeMetric(t *testing.T) {
9898
}
9999
for _, tt := range tests {
100100
t.Run(tt.name, func(t *testing.T) {
101-
c := customMetricsClient{
101+
c := CustomMetricsClient{
102102
tt.fields.client,
103103
}
104104
got, err := c.GetNodeMetric(tt.args.metricName)
@@ -134,6 +134,7 @@ func TestNewClient(t *testing.T) {
134134
t.Run(tt.name, func(t *testing.T) {
135135
got := NewClient(tt.args.config)
136136
if reflect.TypeOf(got) != reflect.TypeOf(dummyRestClientConfig()) {
137+
log.Print("No real test implemented here")
137138
//TODO:add some better verification constructor has worked here.
138139
}
139140
})

pkg/strategies/core/mocks.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,5 @@ func (v *MockStrategy) GetPolicyName() string {
3636

3737
//SetPolicyName sets the policy name of the mock strategy
3838
func (v *MockStrategy) SetPolicyName( policyName string) {
39-
return
39+
4040
}

pkg/strategies/core/operator_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ func TestOrderedList(t *testing.T) {
5353
tests := []struct {
5454
name string
5555
args args
56-
want []nodeSortableMetric
56+
want []NodeSortableMetric
5757
}{
58-
{"less than test", args{testNodeMetricCustomInfo([]string{"node A", "node B", "node C"}, []int64{100, 200, 10}), "LessThan"}, []nodeSortableMetric{{"node C", *resource.NewQuantity(10, resource.DecimalSI)}, {"node A", *resource.NewQuantity(100, resource.DecimalSI)}, {"node B", *resource.NewQuantity(200, resource.DecimalSI)}}},
59-
{"greater than test", args{testNodeMetricCustomInfo([]string{"node A", "node B", "node C"}, []int64{100, 200, 10}), "GreaterThan"}, []nodeSortableMetric{{"node B", *resource.NewQuantity(200, resource.DecimalSI)}, {"node A", *resource.NewQuantity(100, resource.DecimalSI)}, {"node C", *resource.NewQuantity(10, resource.DecimalSI)}}},
58+
{"less than test", args{testNodeMetricCustomInfo([]string{"node A", "node B", "node C"}, []int64{100, 200, 10}), "LessThan"}, []NodeSortableMetric{{"node C", *resource.NewQuantity(10, resource.DecimalSI)}, {"node A", *resource.NewQuantity(100, resource.DecimalSI)}, {"node B", *resource.NewQuantity(200, resource.DecimalSI)}}},
59+
{"greater than test", args{testNodeMetricCustomInfo([]string{"node A", "node B", "node C"}, []int64{100, 200, 10}), "GreaterThan"}, []NodeSortableMetric{{"node B", *resource.NewQuantity(200, resource.DecimalSI)}, {"node A", *resource.NewQuantity(100, resource.DecimalSI)}, {"node C", *resource.NewQuantity(10, resource.DecimalSI)}}},
6060
}
6161
for _, tt := range tests {
6262
t.Run(tt.name, func(t *testing.T) {

pkg/strategies/deschedule/strategy.go

-4
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ func (d *Strategy) StrategyType() string {
2828
//Returns a map of nodeNames as key with an empty value associated with each.
2929
func (d *Strategy) Violated(cache cache.Reader) map[string]interface{} {
3030
violatingNodes := map[string]interface{}{}
31-
output := []string{}
3231
for _, rule := range d.Rules {
3332
nodeMetrics, err := cache.ReadMetric(rule.Metricname)
3433
if err != nil {
@@ -43,9 +42,6 @@ func (d *Strategy) Violated(cache cache.Reader) map[string]interface{} {
4342
}
4443
}
4544
}
46-
for k := range violatingNodes {
47-
output = append(output, k)
48-
}
4945
return violatingNodes
5046
}
5147

pkg/telemetrypolicy/api/v1alpha1/zz_generated_deepcopy.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ func (in *TASPolicy) DeepCopyInto(out *TASPolicy) {
1111
in.ObjectMeta.DeepCopyInto(&out.ObjectMeta)
1212
out.Spec = in.Spec
1313
out.Status = in.Status
14-
return
14+
1515
}
1616

1717
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TASPolicy.
@@ -44,7 +44,7 @@ func (in *TASPolicyList) DeepCopyInto(out *TASPolicyList) {
4444
(*in)[i].DeepCopyInto(&(*out)[i])
4545
}
4646
}
47-
return
47+
4848
}
4949

5050
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TASPolicyList.
@@ -68,7 +68,6 @@ func (in *TASPolicyList) DeepCopyObject() runtime.Object {
6868
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
6969
func (in *TASPolicySpec) DeepCopyInto(out *TASPolicySpec) {
7070
*out = *in
71-
return
7271
}
7372

7473
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TASPolicySpec.
@@ -84,7 +83,6 @@ func (in *TASPolicySpec) DeepCopy() *TASPolicySpec {
8483
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
8584
func (in *TASPolicyStatus) DeepCopyInto(out *TASPolicyStatus) {
8685
*out = *in
87-
return
8886
}
8987

9088
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TASPolicyStatus.

0 commit comments

Comments
 (0)