From f66f94dc80c4b54a0d0b34c3a33193e4e91eb99b Mon Sep 17 00:00:00 2001 From: Alexander Hughes Date: Fri, 28 Feb 2020 09:30:26 -0500 Subject: [PATCH] [#58] Update error strings to be golint compliant Error strings by convention should not end in punctuation, or contain uppercase letters. Relates-To: #58 Change-Id: I027fb21a20f08fdd24cf654f3ae1cbceb3e5a6c6 Signed-off-by: Alexander Hughes --- cmd/config/get_authinfo_test.go | 2 +- cmd/config/get_cluster_test.go | 2 +- ...config-cmd-set-context-too-few-args.golden | 20 ------------------- cmd/config/use_context_test.go | 2 +- pkg/config/config.go | 4 ++-- pkg/container/container_docker_test.go | 18 ++++++++--------- pkg/document/bundle.go | 4 ++-- pkg/document/repo/repo.go | 12 +++++------ pkg/remote/redfish/redfish_test.go | 8 ++++---- pkg/remote/redfish/utils_test.go | 12 +++++------ 10 files changed, 32 insertions(+), 52 deletions(-) delete mode 100644 cmd/config/testdata/TestConfigSetContextGoldenOutput/config-cmd-set-context-too-few-args.golden diff --git a/cmd/config/get_authinfo_test.go b/cmd/config/get_authinfo_test.go index d1cb21c0b..a1bed9294 100644 --- a/cmd/config/get_authinfo_test.go +++ b/cmd/config/get_authinfo_test.go @@ -69,7 +69,7 @@ func TestGetAuthInfoCmd(t *testing.T) { Name: "missing", CmdLine: fmt.Sprintf("%s", missingAuthInfo), 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), }, } diff --git a/cmd/config/get_cluster_test.go b/cmd/config/get_cluster_test.go index 91b0a2056..d531bb67c 100644 --- a/cmd/config/get_cluster_test.go +++ b/cmd/config/get_cluster_test.go @@ -110,7 +110,7 @@ func TestGetClusterCmd(t *testing.T) { Name: "missing", CmdLine: fmt.Sprintf("%s %s", targetFlag, missingCluster), Cmd: cmd.NewCmdConfigGetCluster(settings), - Error: fmt.Errorf("Cluster clusterMissing information was not " + + Error: fmt.Errorf("cluster clustermissing information was not " + "found in the configuration."), }, } diff --git a/cmd/config/testdata/TestConfigSetContextGoldenOutput/config-cmd-set-context-too-few-args.golden b/cmd/config/testdata/TestConfigSetContextGoldenOutput/config-cmd-set-context-too-few-args.golden deleted file mode 100644 index 8d26f0832..000000000 --- a/cmd/config/testdata/TestConfigSetContextGoldenOutput/config-cmd-set-context-too-few-args.golden +++ /dev/null @@ -1,20 +0,0 @@ -Error: accepts 1 arg(s), received 0 -Usage: - set-context NAME [flags] - -Examples: - -# Create a completely new e2e context entry -airshipctl config set-context e2e --namespace=kube-system --manifest=manifest --user=auth-info --cluster-type=target - -# Update the current-context to e2e -airshipctl config set-context e2e - -Flags: - --cluster string sets the cluster for the specified context in the airshipctl config - --cluster-type string sets the cluster-type for the specified context in the airshipctl config - -h, --help help for set-context - --manifest string sets the manifest for the specified context in the airshipctl config - --namespace string sets the namespace for the specified context in the airshipctl config - --user string sets the user for the specified context in the airshipctl config - diff --git a/cmd/config/use_context_test.go b/cmd/config/use_context_test.go index a7a0df49b..415a55133 100644 --- a/cmd/config/use_context_test.go +++ b/cmd/config/use_context_test.go @@ -48,7 +48,7 @@ func TestConfigUseContext(t *testing.T) { Name: "config-use-context-does-not-exist", CmdLine: "foo", Cmd: cmd.NewCmdConfigUseContext(settings), - Error: errors.New("Missing configuration: Context with name 'foo'"), + Error: errors.New("missing configuration: context with name 'foo'"), }, } diff --git a/pkg/config/config.go b/pkg/config/config.go index 3cba3f3f1..cdb6585b3 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -59,7 +59,7 @@ func (c *Config) LoadConfig(airshipConfigPath, kubeConfigPath string) error { // * the file at airshipConfigPath cannot be marshaled into Config func (c *Config) loadFromAirConfig(airshipConfigPath string) error { if airshipConfigPath == "" { - return errors.New("Configuration file location was not provided.") + return errors.New("configuration file location was not provided") } // Remember where I loaded the Config from @@ -983,7 +983,7 @@ func ValidClusterType(clusterType string) error { return nil } } - return fmt.Errorf("Cluster Type must be one of %v", AllClusterTypes) + return fmt.Errorf("cluster type must be one of %v", AllClusterTypes) } /* ______________________________ diff --git a/pkg/container/container_docker_test.go b/pkg/container/container_docker_test.go index 34f48e302..1c6bf872c 100644 --- a/pkg/container/container_docker_test.go +++ b/pkg/container/container_docker_test.go @@ -115,7 +115,7 @@ func getDockerContainerMock(mdc mockDockerClient) *DockerContainer { } func TestGetCmd(t *testing.T) { - testError := fmt.Errorf("Inspect error") + testError := fmt.Errorf("inspect error") tests := []struct { cmd []string mockDockerClient mockDockerClient @@ -170,7 +170,7 @@ func TestGetCmd(t *testing.T) { } func TestGetImageId(t *testing.T) { - testError := fmt.Errorf("Img List Error") + testError := fmt.Errorf("img list error") tests := []struct { url string mockDockerClient mockDockerClient @@ -208,7 +208,7 @@ func TestGetImageId(t *testing.T) { } func TestImagePull(t *testing.T) { - testError := fmt.Errorf("Image Pull Error") + testError := fmt.Errorf("image pull rror") tests := []struct { mockDockerClient mockDockerClient expectedErr error @@ -248,10 +248,10 @@ func TestGetId(t *testing.T) { } func TestRunCommand(t *testing.T) { - imageListError := fmt.Errorf("Image List Error") - attachError := fmt.Errorf("Attach error") - containerStartError := fmt.Errorf("Container Start error") - containerWaitError := fmt.Errorf("Container Wait Error") + imageListError := fmt.Errorf("image list error") + attachError := fmt.Errorf("attach error") + containerStartError := fmt.Errorf("container start error") + containerWaitError := fmt.Errorf("container wait error") tests := []struct { cmd []string containerInput io.Reader @@ -371,7 +371,7 @@ func TestRunCommand(t *testing.T) { } func TestRunCommandOutput(t *testing.T) { - testError := fmt.Errorf("Img List Error") + testError := fmt.Errorf("img list error") tests := []struct { cmd []string containerInput io.Reader @@ -421,7 +421,7 @@ func TestRunCommandOutput(t *testing.T) { } func TestNewDockerContainer(t *testing.T) { - testError := fmt.Errorf("Image Pull Error") + testError := fmt.Errorf("image pull error") type resultStruct struct { tag string imageUrl string diff --git a/pkg/document/bundle.go b/pkg/document/bundle.go index 011c15d3a..3f39c5372 100644 --- a/pkg/document/bundle.go +++ b/pkg/document/bundle.go @@ -180,9 +180,9 @@ func (b *BundleFactory) GetByName(name string) (Document, error) { // by adding strongly typed errors switch found := len(resSet); { case found == 0: - return &DocumentFactory{}, fmt.Errorf("No documents found with name %s", name) + return &DocumentFactory{}, fmt.Errorf("no documents found with name %s", name) case found > 1: - return &DocumentFactory{}, fmt.Errorf("More than one document found with name %s", name) + return &DocumentFactory{}, fmt.Errorf("more than one document found with name %s", name) default: return NewDocument(resSet[0]) } diff --git a/pkg/document/repo/repo.go b/pkg/document/repo/repo.go index e074edbdf..80b006bd7 100644 --- a/pkg/document/repo/repo.go +++ b/pkg/document/repo/repo.go @@ -26,9 +26,9 @@ const ( ) var ( - ErrNoOpenRepo = errors.New("No open repository is stored") - ErrRemoteRefNotImplemented = errors.New("RemoteRef is not yet implemented") - ErrCantParseUrl = errors.New("Couldn't get target directory from URL") + ErrNoOpenRepo = errors.New("no open repository is stored") + ErrRemoteRefNotImplemented = errors.New("remoteref is not yet implemented") + ErrCantParseUrl = errors.New("could not get target directory from url") ) type OptionsBuilder interface { @@ -94,7 +94,7 @@ func (repo *Repository) Update(force bool) error { } err = repo.Driver.Fetch(repo.ToFetchOptions(auth)) if err != nil && err != git.NoErrAlreadyUpToDate { - return fmt.Errorf("Failed to fetch refs for repository %v: %w", repo.Name, err) + return fmt.Errorf("failed to fetch refs for repository %v: %w", repo.Name, err) } return repo.Checkout(force) } @@ -108,7 +108,7 @@ func (repo *Repository) Checkout(enforce bool) error { co := repo.ToCheckoutOptions(enforce) tree, err := repo.Driver.Worktree() if err != nil { - return fmt.Errorf("Cloud not get worktree from the repo, %w", err) + return fmt.Errorf("could not get worktree from the repo, %w", err) } return tree.Checkout(co) } @@ -124,7 +124,7 @@ func (repo *Repository) Clone() error { log.Debugf("Attempting to clone the repository %s", repo.Name) auth, err := repo.ToAuth() if err != nil { - return fmt.Errorf("Failed to build Auth options for repository %v: %w", repo.Name, err) + return fmt.Errorf("failed to build auth options for repository %v: %w", repo.Name, err) } return repo.Driver.Clone(repo.ToCloneOptions(auth)) diff --git a/pkg/remote/redfish/redfish_test.go b/pkg/remote/redfish/redfish_test.go index d2a489662..a995bf94e 100644 --- a/pkg/remote/redfish/redfish_test.go +++ b/pkg/remote/redfish/redfish_test.go @@ -84,7 +84,7 @@ func TestRedfishRemoteDirectGetSystemNetworkError(t *testing.T) { defer m.AssertExpectations(t) systemID := computerSystemID - realErr := fmt.Errorf("Server request timeout") + realErr := fmt.Errorf("server request timeout") httpResp := &http.Response{ StatusCode: 408, } @@ -109,7 +109,7 @@ func TestRedfishRemoteDirectInvalidIsoPath(t *testing.T) { localRDCfg := rDCfg localRDCfg.IsoPath = "bogus/path/to.iso" - errStr := "Invalid remote boot path" + errStr := "invalid remote boot path" realErr := fmt.Errorf(errStr) httpResp := &http.Response{ StatusCode: 500, @@ -163,7 +163,7 @@ func TestRedfishRemoteDirectSetSystemBootSourceFailed(t *testing.T) { m.On("InsertVirtualMedia", context.Background(), "manager-1", "Cd", mock.Anything). Return(redfishClient.RedfishError{}, nil, nil) - realErr := fmt.Errorf("Unauthorized") + realErr := fmt.Errorf("unauthorized") httpResp := &http.Response{ StatusCode: 401, } @@ -195,7 +195,7 @@ func TestRedfishRemoteDirectSystemRebootFailed(t *testing.T) { Times(1). Return(redfishClient.ComputerSystem{}, nil, nil) - realErr := fmt.Errorf("Unauthorized") + realErr := fmt.Errorf("unauthorized") httpResp := &http.Response{ StatusCode: 401, } diff --git a/pkg/remote/redfish/utils_test.go b/pkg/remote/redfish/utils_test.go index c204e8caa..643959bbc 100644 --- a/pkg/remote/redfish/utils_test.go +++ b/pkg/remote/redfish/utils_test.go @@ -22,7 +22,7 @@ func TestRedfishErrorNoError(t *testing.T) { } func TestRedfishErrorNonNilErrorWithoutHttpResp(t *testing.T) { - realErr := fmt.Errorf("Sample error") + realErr := fmt.Errorf("sample error") err := ScreenRedfishError(nil, realErr) assert.Error(t, err) _, ok := err.(*RedfishClientError) @@ -30,7 +30,7 @@ func TestRedfishErrorNonNilErrorWithoutHttpResp(t *testing.T) { } func TestRedfishErrorNonNilErrorWithHttpRespError(t *testing.T) { - realErr := fmt.Errorf("Sample error") + realErr := fmt.Errorf("sample error") httpResp := &http.Response{StatusCode: 408} err := ScreenRedfishError(httpResp, realErr) @@ -46,7 +46,7 @@ func TestRedfishErrorNonNilErrorWithHttpRespError(t *testing.T) { } func TestRedfishErrorNonNilErrorWithHttpRespOK(t *testing.T) { - realErr := fmt.Errorf("Sample error") + realErr := fmt.Errorf("sample error") httpResp := &http.Response{StatusCode: 204} err := ScreenRedfishError(httpResp, realErr) @@ -122,7 +122,7 @@ func TestRedfishUtilRebootSystemForceOffError2(t *testing.T) { defer m.AssertExpectations(t) ctx := context.Background() - realErr := fmt.Errorf("Unauthorized") + realErr := fmt.Errorf("unauthorized") httpResp := &http.Response{ StatusCode: 401, } @@ -142,7 +142,7 @@ func TestRedfishUtilRebootSystemForceOffError(t *testing.T) { defer m.AssertExpectations(t) ctx := context.Background() - realErr := fmt.Errorf("Unauthorized") + realErr := fmt.Errorf("unauthorized") httpResp := &http.Response{ StatusCode: 401, } @@ -167,7 +167,7 @@ func TestRedfishUtilRebootSystemTurningOnError(t *testing.T) { Times(1). Return(redfishClient.RedfishError{}, nil, nil) - realErr := fmt.Errorf("Unauthorized") + realErr := fmt.Errorf("unauthorized") httpResp := &http.Response{ StatusCode: 401, }