Merge "Enable golint as part of golangci-lint."

This commit is contained in:
Zuul 2020-05-20 19:29:25 +00:00 committed by Gerrit Code Review
commit faaae536ce
7 changed files with 31 additions and 29 deletions
.golangci.yaml
cmd/config
pkg
document/plugin/replacement/v1alpha1
environment
k8s/kubectl
phase/apply

@ -210,3 +210,4 @@ linters:
- unused # Checks Go code for unused constants, variables, functions and types
- varcheck # Finds unused global variables and constants
- whitespace # Tool for detection of leading and trailing whitespace NOTE(howell): This linter does _not_ check for trailing whitespace in multiline strings
- golint # Finds all coding style mistakes

@ -69,8 +69,8 @@ func TestGetContextCmd(t *testing.T) {
Name: "missing",
CmdLine: fmt.Sprintf("%s", missingContext),
Cmd: cmd.NewGetContextCommand(settings),
Error: fmt.Errorf(`Context %s information was not
found in the configuration.`, missingContext),
Error: fmt.Errorf("context %s information was not found in the configuration",
missingContext),
},
{
Name: "get-current-context",

@ -56,7 +56,7 @@ func (e ErrMultipleResources) Error() string {
return fmt.Sprintf("found more than one resources matching from %v", e.ResList)
}
// ErrResourceNotFound returned if a replacement source resource does not exist in resource map
// ErrSourceNotFound returned if a replacement source resource does not exist in resource map
type ErrSourceNotFound struct {
ObjRef *types.Target
}
@ -74,7 +74,7 @@ func (e ErrSourceNotFound) Error() string {
return fmt.Sprintf("failed to find any source resources identified by %s", strings.TrimSpace(resFilter))
}
// ErrSelectorNotFound returned if a replacement target resource does not exist in the resource map
// ErrTargetNotFound returned if a replacement target resource does not exist in the resource map
type ErrTargetNotFound struct {
ObjRef *types.Selector
}

@ -138,6 +138,7 @@ func initPluginPath() {
pluginPath = filepath.Join(homeDir, config.AirshipConfigDir, config.AirshipPluginPath)
}
// PluginPath returns the kustomize plugin path
func PluginPath() string {
pluginPathLock.Lock()
defer pluginPathLock.Unlock()

@ -30,12 +30,12 @@ import (
var (
filenameRC = "testdata/replicationcontroller.yaml"
testStreams = genericclioptions.NewTestIOStreamsDiscard()
ToDiscoveryError = errors.New("ToDiscoveryError")
DynamicClientError = errors.New("DynamicClientError")
ValidateError = errors.New("ValidateError")
ToRESTMapperError = errors.New("ToRESTMapperError")
NamespaceError = errors.New("NamespaceError")
testStreams = genericclioptions.NewTestIOStreamsDiscard()
ErrToDiscoveryError = errors.New("ErrToDiscoveryError")
ErrDynamicClientError = errors.New("ErrDynamicClientError")
ErrValidateError = errors.New("ErrValidateError")
ErrToRESTMapperError = errors.New("ErrToRESTMapperError")
ErrNamespaceError = errors.New("ErrNamespaceError")
)
func TestApplyOptionsRun(t *testing.T) {
@ -57,27 +57,27 @@ func TestNewApplyOptionsFactoryFailures(t *testing.T) {
expectedError error
}{
{
f: k8stest.NewMockKubectlFactory().WithToDiscoveryClientByError(nil, ToDiscoveryError),
expectedError: ToDiscoveryError,
f: k8stest.NewMockKubectlFactory().WithToDiscoveryClientByError(nil, ErrToDiscoveryError),
expectedError: ErrToDiscoveryError,
},
{
f: k8stest.NewMockKubectlFactory().WithDynamicClientByError(nil, DynamicClientError),
expectedError: DynamicClientError,
f: k8stest.NewMockKubectlFactory().WithDynamicClientByError(nil, ErrDynamicClientError),
expectedError: ErrDynamicClientError,
},
{
f: k8stest.NewMockKubectlFactory().WithValidatorByError(nil, ValidateError),
expectedError: ValidateError,
f: k8stest.NewMockKubectlFactory().WithValidatorByError(nil, ErrValidateError),
expectedError: ErrValidateError,
},
{
f: k8stest.NewMockKubectlFactory().WithToRESTMapperByError(nil, ToRESTMapperError),
expectedError: ToRESTMapperError,
f: k8stest.NewMockKubectlFactory().WithToRESTMapperByError(nil, ErrToRESTMapperError),
expectedError: ErrToRESTMapperError,
},
{
f: k8stest.NewMockKubectlFactory().
WithToRawKubeConfigLoaderByError(k8stest.
NewMockClientConfig().
WithNamespace("", false, NamespaceError)),
expectedError: NamespaceError,
WithNamespace("", false, ErrNamespaceError)),
expectedError: ErrNamespaceError,
},
}
for _, test := range tests {

@ -32,8 +32,8 @@ var (
kubeconfigPath = "testdata/kubeconfig.yaml"
fixtureDir = "testdata/"
writeOutError = errors.New("writeOutError")
TempFileError = errors.New("TempFileError")
ErrWriteOutError = errors.New("ErrWriteOutError")
ErrTempFileError = errors.New("ErrTempFileError")
)
type MockFileSystem struct {
@ -99,17 +99,17 @@ func TestApply(t *testing.T) {
},
},
{
expectedErr: writeOutError,
expectedErr: ErrWriteOutError,
fs: MockFileSystem{
MockTempFile: func() (document.File, error) { return nil, writeOutError }},
MockTempFile: func() (document.File, error) { return nil, ErrWriteOutError }},
},
{
expectedErr: TempFileError,
expectedErr: ErrTempFileError,
fs: MockFileSystem{
MockRemoveAll: func() error { return nil },
MockTempFile: func() (document.File, error) {
return TestFile{
MockWrite: func() (int, error) { return 0, TempFileError },
MockWrite: func() (int, error) { return 0, ErrTempFileError },
MockName: func() string { return filenameRC },
MockClose: func() error { return nil },
}, nil

@ -37,7 +37,7 @@ const (
)
var (
DynamicClientError = errors.New("DynamicClientError")
ErrDynamicClientError = errors.New("ErrDynamicClientError")
)
func TestDeploy(t *testing.T) {
@ -62,8 +62,8 @@ func TestDeploy(t *testing.T) {
client: fake.NewClient(fake.WithKubectl(
kubectl.NewKubectl(k8sutils.
NewMockKubectlFactory().
WithDynamicClientByError(nil, DynamicClientError)))),
expectedError: DynamicClientError,
WithDynamicClientByError(nil, ErrDynamicClientError)))),
expectedError: ErrDynamicClientError,
},
{
expectedError: nil,