-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(ci): add golangci-lint and refactor according to the result (#294)
* chore: add golangci-lint check config and update Makefile for check * fix: fix according to golangci-lint * fix: rename Api to API * fix: fix sharedVolumeAndMountBuild SetVolumeMountSize non-zero slice * fix: remove overlapped Build method from shardingSphereProxyContainerBuilder * chore: add license header
- Loading branch information
Showing
18 changed files
with
265 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one or more | ||
# contributor license agreements. See the NOTICE file distributed with | ||
# this work for additional information regarding copyright ownership. | ||
# The ASF licenses this file to You under the Apache License, Version 2.0 | ||
# (the "License"); you may not use this file except in compliance with | ||
# the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
run: | ||
timeout: 10m | ||
linters: | ||
disable-all: true | ||
enable: | ||
- ineffassign | ||
- typecheck | ||
- varcheck | ||
- unused | ||
- structcheck | ||
- deadcode | ||
- gosimple | ||
- goimports | ||
- errcheck | ||
- staticcheck | ||
- stylecheck | ||
- gosec | ||
- asciicheck | ||
- bodyclose | ||
- exportloopref | ||
- rowserrcheck | ||
- makezero | ||
- durationcheck | ||
- prealloc | ||
- predeclared | ||
|
||
# Refers: https://gist.github.com/maratori/47a4d00457a92aa426dbd48a18776322 | ||
linters-settings: | ||
cyclop: | ||
# The maximal code complexity to report. | ||
# Default: 10 | ||
max-complexity: 30 | ||
# The maximal average package complexity. | ||
# If it's higher than 0.0 (float) the check is enabled | ||
# Default: 0.0 | ||
package-average: 10.0 | ||
errcheck: | ||
# Report about not checking of errors in type assertions: `a := b.(MyStruct)`. | ||
# Such cases aren't reported by default. | ||
# Default: false | ||
check-type-assertions: true | ||
exhaustive: | ||
# Program elements to check for exhaustiveness. | ||
# Default: [ switch ] | ||
check: | ||
- switch | ||
- map | ||
funlen: | ||
# Checks the number of lines in a function. | ||
# If lower than 0, disable the check. | ||
# Default: 60 | ||
lines: 100 | ||
# Checks the number of statements in a function. | ||
# If lower than 0, disable the check. | ||
# Default: 40 | ||
statements: 50 | ||
gocognit: | ||
# Minimal code complexity to report. | ||
# Default: 30 (but we recommend 10-20) | ||
min-complexity: 20 | ||
issues: | ||
exclude-rules: | ||
- path: _test\.go | ||
linters: | ||
- errcheck | ||
- gosec | ||
- rowserrcheck | ||
- makezero |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
shardingsphere-operator/pkg/controllers/compute_node_controller_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package controllers | ||
|
||
import ( | ||
"testing" | ||
|
||
v1 "k8s.io/api/core/v1" | ||
) | ||
|
||
func Test_GetReadyProxyInstances(t *testing.T) { | ||
// create sample PodList | ||
podlist := v1.PodList{ | ||
Items: []v1.Pod{ | ||
{ | ||
Status: v1.PodStatus{ | ||
Phase: v1.PodRunning, | ||
Conditions: []v1.PodCondition{ | ||
{ | ||
Type: v1.PodReady, | ||
Status: v1.ConditionTrue, | ||
}, | ||
}, | ||
ContainerStatuses: []v1.ContainerStatus{ | ||
{ | ||
Name: "shardingsphere-proxy", | ||
Ready: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
Status: v1.PodStatus{ | ||
Phase: v1.PodRunning, | ||
Conditions: []v1.PodCondition{ | ||
{ | ||
Type: v1.PodReady, | ||
Status: v1.ConditionTrue, | ||
}, | ||
}, | ||
ContainerStatuses: []v1.ContainerStatus{ | ||
{ | ||
Name: "another-container", | ||
Ready: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
Status: v1.PodStatus{ | ||
Phase: v1.PodRunning, | ||
Conditions: []v1.PodCondition{ | ||
{ | ||
Type: v1.PodReady, | ||
Status: v1.ConditionFalse, | ||
}, | ||
}, | ||
ContainerStatuses: []v1.ContainerStatus{ | ||
{ | ||
Name: "shardingsphere-proxy", | ||
Ready: false, | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
Status: v1.PodStatus{ | ||
Phase: v1.PodPending, | ||
Conditions: []v1.PodCondition{ | ||
{ | ||
Type: v1.PodReady, | ||
Status: v1.ConditionTrue, | ||
}, | ||
}, | ||
ContainerStatuses: []v1.ContainerStatus{ | ||
{ | ||
Name: "shardingsphere-proxy", | ||
Ready: true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
// expected result is 1 because only one pod has a ready shardingsphere-proxy container | ||
expected := int32(1) | ||
|
||
// call the function to get the actual result | ||
actual := getReadyProxyInstances(podlist) | ||
|
||
// compare the expected and actual results | ||
if actual != expected { | ||
t.Errorf("getReadyInstances returned %d, expected %d", actual, expected) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.