Refactor of codebase addressing IDE errors

Goland is complaining of a number of bad practices, and unused code.
This patchset addresses some of those complaints, such as:
- struct initialization without field names
- error string should not be capitalized or end with punctuation
- name starts with package name
- duplicate yaml keys
- snake case
- redundant parentheses

For the http.Transport redundant parentheses, the lint target fails
without the use of //nolint:errcheck so it has been added as
(currently) there is no potential for there to be an error returned
see [0] for example.

[0] https://golang.org/src/net/http/transport.go#L42

Change-Id: Ib1b20639c9b6e9be097ef1f158ecd7472f578488
Signed-off-by: Alexander Hughes <Alexander.Hughes@pm.me>
This commit is contained in:
Alexander Hughes 2020-04-14 14:13:20 -04:00
parent 8438935cfe
commit c70f4a2742
13 changed files with 22 additions and 32 deletions

View File

@ -20,15 +20,10 @@ import (
"opendev.org/airship/airshipctl/pkg/environment" "opendev.org/airship/airshipctl/pkg/environment"
) )
var (
// ClusterUse subcommand string
ClusterUse = "cluster"
)
// NewClusterCommand returns cobra command object of the airshipctl cluster and adds it's subcommands. // NewClusterCommand returns cobra command object of the airshipctl cluster and adds it's subcommands.
func NewClusterCommand(rootSettings *environment.AirshipCTLSettings) *cobra.Command { func NewClusterCommand(rootSettings *environment.AirshipCTLSettings) *cobra.Command {
clusterRootCmd := &cobra.Command{ clusterRootCmd := &cobra.Command{
Use: ClusterUse, Use: "cluster",
// TODO: (kkalynovskyi) Add more description when more subcommands are added // TODO: (kkalynovskyi) Add more description when more subcommands are added
Short: "Control Kubernetes cluster", Short: "Control Kubernetes cluster",
Long: "Interactions with Kubernetes cluster, such as get status, deploy initial infrastructure", Long: "Interactions with Kubernetes cluster, such as get status, deploy initial infrastructure",

View File

@ -69,7 +69,7 @@ func TestGetAuthInfoCmd(t *testing.T) {
CmdLine: fmt.Sprintf("%s", missingAuthInfo), CmdLine: fmt.Sprintf("%s", missingAuthInfo),
Cmd: cmd.NewCmdConfigGetAuthInfo(settings), Cmd: cmd.NewCmdConfigGetAuthInfo(settings),
Error: fmt.Errorf("user %s information was not "+ Error: fmt.Errorf("user %s information was not "+
"found in the configuration.", missingAuthInfo), "found in the configuration", missingAuthInfo),
}, },
} }

View File

@ -110,7 +110,7 @@ func TestGetClusterCmd(t *testing.T) {
CmdLine: fmt.Sprintf("%s %s", targetFlag, missingCluster), CmdLine: fmt.Sprintf("%s %s", targetFlag, missingCluster),
Cmd: cmd.NewCmdConfigGetCluster(settings), Cmd: cmd.NewCmdConfigGetCluster(settings),
Error: fmt.Errorf("cluster clustermissing information was not " + Error: fmt.Errorf("cluster clustermissing information was not " +
"found in the configuration."), "found in the configuration"),
}, },
} }

View File

@ -24,7 +24,7 @@ import (
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/dynamic" "k8s.io/client-go/dynamic"
dynamic_fake "k8s.io/client-go/dynamic/fake" dynamicFake "k8s.io/client-go/dynamic/fake"
"opendev.org/airship/airshipctl/pkg/cluster" "opendev.org/airship/airshipctl/pkg/cluster"
"opendev.org/airship/airshipctl/pkg/document" "opendev.org/airship/airshipctl/pkg/document"
@ -149,7 +149,7 @@ func TestGetStatusForResource(t *testing.T) {
ByGvk("example.com", "v1", "Missing"). ByGvk("example.com", "v1", "Missing").
ByName("missing-resource"), ByName("missing-resource"),
testClient: makeTestClient(), testClient: makeTestClient(),
err: cluster.ErrResourceNotFound{"missing-resource"}, err: cluster.ErrResourceNotFound{Resource: "missing-resource"},
}, },
} }
@ -180,7 +180,7 @@ func TestGetStatusForResource(t *testing.T) {
func makeTestClient(obj ...runtime.Object) fake.Client { func makeTestClient(obj ...runtime.Object) fake.Client {
testClient := fake.Client{ testClient := fake.Client{
MockDynamicClient: func() dynamic.Interface { MockDynamicClient: func() dynamic.Interface {
return dynamic_fake.NewSimpleDynamicClient(runtime.NewScheme(), obj...) return dynamicFake.NewSimpleDynamicClient(runtime.NewScheme(), obj...)
}, },
} }
return testClient return testClient

View File

@ -3,7 +3,6 @@
# It is included in tests to assure backward compatibility # It is included in tests to assure backward compatibility
apiVersion: apiextensions.k8s.io/v1beta1 apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition kind: CustomResourceDefinition
metadata:
metadata: metadata:
name: legacies.example.com name: legacies.example.com
annotations: annotations:

View File

@ -393,7 +393,7 @@ func TestRunCommand(t *testing.T) {
return resC, nil return resC, nil
}, },
containerLogs: func() (io.ReadCloser, error) { containerLogs: func() (io.ReadCloser, error) {
return nil, fmt.Errorf("Logs error") return nil, fmt.Errorf("logs error")
}, },
}, },
expectedErr: ErrRunContainerCommand{Cmd: "docker logs testID"}, expectedErr: ErrRunContainerCommand{Cmd: "docker logs testID"},

View File

@ -32,17 +32,17 @@ type FileSystem interface {
TempFile(string, string) (File, error) TempFile(string, string) (File, error)
} }
// DocumentFs is adaptor to TempFile // Fs is adaptor to TempFile
type DocumentFs struct { type Fs struct {
fs.FileSystem fs.FileSystem
} }
// NewDocumentFs returns an instalce of DocumentFs // NewDocumentFs returns an instance of Fs
func NewDocumentFs() FileSystem { func NewDocumentFs() FileSystem {
return &DocumentFs{FileSystem: fs.MakeFsOnDisk()} return &Fs{FileSystem: fs.MakeFsOnDisk()}
} }
// TempFile creates file in temporary filesystem, at default os.TempDir // TempFile creates file in temporary filesystem, at default os.TempDir
func (dfs DocumentFs) TempFile(tmpDir string, prefix string) (File, error) { func (dfs Fs) TempFile(tmpDir string, prefix string) (File, error) {
return ioutil.TempFile(tmpDir, prefix) return ioutil.TempFile(tmpDir, prefix)
} }

View File

@ -203,7 +203,7 @@ func NewClient(ephemeralNodeID string,
// We clone the default transport to ensure when we customize the transport // We clone the default transport to ensure when we customize the transport
// that we are providing it sane timeouts and other defaults that we would // that we are providing it sane timeouts and other defaults that we would
// normally get when not overriding the transport // normally get when not overriding the transport
defaultTransportCopy := (http.DefaultTransport.(*http.Transport)) defaultTransportCopy := http.DefaultTransport.(*http.Transport) //nolint:errcheck
transport := defaultTransportCopy.Clone() transport := defaultTransportCopy.Clone()
if insecure { if insecure {

View File

@ -26,7 +26,7 @@ import (
) )
const ( const (
RedfishURLSchemeSeparator = "+" URLSchemeSeparator = "+"
) )
// GetResourceIDFromURL returns a parsed Redfish resource ID // GetResourceIDFromURL returns a parsed Redfish resource ID

View File

@ -25,10 +25,6 @@ import (
"opendev.org/airship/airshipctl/pkg/remote/redfish" "opendev.org/airship/airshipctl/pkg/remote/redfish"
) )
const (
AirshipHostKind string = "BareMetalHost"
)
// Adapter bridges the gap between out-of-band clients. It can hold any type of OOB client, e.g. Redfish. // Adapter bridges the gap between out-of-band clients. It can hold any type of OOB client, e.g. Redfish.
type Adapter struct { type Adapter struct {
OOBClient Client OOBClient Client
@ -51,7 +47,7 @@ func (a *Adapter) configureClient(remoteURL string) error {
} }
baseURL := fmt.Sprintf("%s://%s", rfURL.Scheme, rfURL.Host) baseURL := fmt.Sprintf("%s://%s", rfURL.Scheme, rfURL.Host)
schemeSplit := strings.Split(rfURL.Scheme, redfish.RedfishURLSchemeSeparator) schemeSplit := strings.Split(rfURL.Scheme, redfish.URLSchemeSeparator)
if len(schemeSplit) > 1 { if len(schemeSplit) > 1 {
baseURL = fmt.Sprintf("%s://%s", schemeSplit[len(schemeSplit)-1], rfURL.Host) baseURL = fmt.Sprintf("%s://%s", schemeSplit[len(schemeSplit)-1], rfURL.Host)
} }

View File

@ -113,7 +113,7 @@ func TestDoRemoteDirectRedfish(t *testing.T) {
a, err := NewAdapter(settings) a, err := NewAdapter(settings)
assert.NoError(t, err) assert.NoError(t, err)
ctx, rMock, err := redfishutils.NewClient(systemID, isoURL, redfishURL, false, false, "admin", "password") ctx, rMock, err := redfishutils.NewClient(systemID, isoURL, redfishURL, "admin", "password")
assert.NoError(t, err) assert.NoError(t, err)
rMock.On("SetVirtualMedia", a.Context, isoURL).Times(1).Return(nil) rMock.On("SetVirtualMedia", a.Context, isoURL).Times(1).Return(nil)
@ -140,7 +140,7 @@ func TestDoRemoteDirectRedfishVirtualMediaError(t *testing.T) {
a, err := NewAdapter(settings) a, err := NewAdapter(settings)
assert.NoError(t, err) assert.NoError(t, err)
ctx, rMock, err := redfishutils.NewClient(systemID, isoURL, redfishURL, false, false, "admin", "password") ctx, rMock, err := redfishutils.NewClient(systemID, isoURL, redfishURL, "admin", "password")
assert.NoError(t, err) assert.NoError(t, err)
expectedErr := redfish.ErrRedfishClient{Message: "Unable to set virtual media."} expectedErr := redfish.ErrRedfishClient{Message: "Unable to set virtual media."}
@ -169,7 +169,7 @@ func TestDoRemoteDirectRedfishBootSourceError(t *testing.T) {
a, err := NewAdapter(settings) a, err := NewAdapter(settings)
assert.NoError(t, err) assert.NoError(t, err)
ctx, rMock, err := redfishutils.NewClient(systemID, isoURL, redfishURL, false, false, "admin", "password") ctx, rMock, err := redfishutils.NewClient(systemID, isoURL, redfishURL, "admin", "password")
assert.NoError(t, err) assert.NoError(t, err)
rMock.On("SetVirtualMedia", a.Context, isoURL).Times(1).Return(nil) rMock.On("SetVirtualMedia", a.Context, isoURL).Times(1).Return(nil)
@ -199,7 +199,7 @@ func TestDoRemoteDirectRedfishRebootError(t *testing.T) {
a, err := NewAdapter(settings) a, err := NewAdapter(settings)
assert.NoError(t, err) assert.NoError(t, err)
ctx, rMock, err := redfishutils.NewClient(systemID, isoURL, redfishURL, false, false, "admin", "password") ctx, rMock, err := redfishutils.NewClient(systemID, isoURL, redfishURL, "admin", "password")
assert.NoError(t, err) assert.NoError(t, err)
rMock.On("SetVirtualMedia", a.Context, isoURL).Times(1).Return(nil) rMock.On("SetVirtualMedia", a.Context, isoURL).Times(1).Return(nil)

View File

@ -110,8 +110,8 @@ func (m *MockClient) SystemPowerStatus(ctx context.Context, systemID string) (st
// NewClient returns a mocked Redfish client in order to test functions that use the Redfish client without making any // NewClient returns a mocked Redfish client in order to test functions that use the Redfish client without making any
// Redfish API calls. // Redfish API calls.
func NewClient(ephemeralNodeID string, isoPath string, redfishURL string, insecure bool, func NewClient(ephemeralNodeID string, isoPath string, redfishURL string, username string,
proxy bool, username string, password string) (context.Context, *MockClient, error) { password string) (context.Context, *MockClient, error) {
var ctx context.Context var ctx context.Context
if username != "" && password != "" { if username != "" && password != "" {
ctx = context.WithValue( ctx = context.WithValue(

View File

@ -20,7 +20,7 @@ import (
func SetupTestFs(t *testing.T, fixtureDir string) document.FileSystem { func SetupTestFs(t *testing.T, fixtureDir string) document.FileSystem {
t.Helper() t.Helper()
x := &document.DocumentFs{FileSystem: fs.MakeFsInMemory()} x := &document.Fs{FileSystem: fs.MakeFsInMemory()}
files, err := ioutil.ReadDir(fixtureDir) files, err := ioutil.ReadDir(fixtureDir)
require.NoErrorf(t, err, "Failed to read fixture directory %s", fixtureDir) require.NoErrorf(t, err, "Failed to read fixture directory %s", fixtureDir)