diff --git a/cmd/krew/cmd/search.go b/cmd/krew/cmd/search.go index 9d35f28e..72961f96 100644 --- a/cmd/krew/cmd/search.go +++ b/cmd/krew/cmd/search.go @@ -96,7 +96,7 @@ Examples: func limitString(s string, length int) string { if len(s) > length && length > 3 { - s = string(s[:length-3]) + "..." + s = s[:length-3] + "..." } return s } diff --git a/pkg/download/downloader.go b/pkg/download/downloader.go index 6a17a643..ab0d767a 100644 --- a/pkg/download/downloader.go +++ b/pkg/download/downloader.go @@ -23,7 +23,6 @@ import ( "io/ioutil" "net/http" "os" - "path" "path/filepath" "strings" @@ -166,8 +165,7 @@ var defaultExtractors = map[string]extractor{ "application/x-gzip": extractTARGZ, } -func extractArchive(filename, dst string, at io.ReaderAt, size int64) error { - // TODO(lbb): Keep the filename for later direct download +func extractArchive(dst string, at io.ReaderAt, size int64) error { // TODO(ahmetb) This package is not architected well, this method should not // be receiving this many args. Primary problem is at GetInsecure and // GetWithSha256 methods that embed extraction in them, which is orthogonal. @@ -206,5 +204,5 @@ func (d Downloader) Get(uri, dst string) error { if err != nil { return errors.Wrapf(err, "failed to get the uri %q", uri) } - return extractArchive(path.Base(uri), dst, body, size) + return extractArchive(dst, body, size) } diff --git a/pkg/download/downloader_test.go b/pkg/download/downloader_test.go index d0132ab3..6c61a858 100644 --- a/pkg/download/downloader_test.go +++ b/pkg/download/downloader_test.go @@ -145,7 +145,7 @@ func collectFiles(t *testing.T, scanPath string) []string { } fp = strings.TrimPrefix(fp, scanPath) if info.IsDir() { - fp = fp + "/" + fp += "/" } outFiles = append(outFiles, fp) return nil @@ -456,7 +456,7 @@ func Test_extractArchive(t *testing.T) { return } - if err := extractArchive(tt.args.filename, tt.args.dst, fd, st.Size()); (err != nil) != tt.wantErr { + if err := extractArchive(tt.args.dst, fd, st.Size()); (err != nil) != tt.wantErr { t.Errorf("extractArchive() error = %v, wantErr %v", err, tt.wantErr) } }) diff --git a/pkg/download/fetch_test.go b/pkg/download/fetch_test.go deleted file mode 100644 index 275e7cc6..00000000 --- a/pkg/download/fetch_test.go +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2019 The Kubernetes Authors. -// -// Licensed 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 download - -import "io" - -// FakeFetcher is used for testing. -type FakeFetcher struct { - io.ReadCloser -} - -// Get gets the file and returns an stream to read the file. -func (ff FakeFetcher) Get(uri string) (io.ReadCloser, error) { - return ff.ReadCloser, nil -} diff --git a/pkg/environment/environment.go b/pkg/environment/environment.go index bb98decf..d86b543d 100644 --- a/pkg/environment/environment.go +++ b/pkg/environment/environment.go @@ -32,7 +32,7 @@ type Paths struct { } // MustGetKrewPaths returns the inferred paths for krew. By default, it assumes -// $HOME/.krew as the base path, but can be overriden via KREW_ROOT environment +// $HOME/.krew as the base path, but can be overridden via KREW_ROOT environment // variable. func MustGetKrewPaths() Paths { base := filepath.Join(homedir.HomeDir(), ".krew") diff --git a/pkg/installation/install.go b/pkg/installation/install.go index 5a6d4277..4fca7026 100644 --- a/pkg/installation/install.go +++ b/pkg/installation/install.go @@ -183,7 +183,7 @@ func pluginNameToBin(name string, isWindows bool) string { name = strings.Replace(name, "-", "_", -1) name = "kubectl-" + name if isWindows { - name = name + ".exe" + name += ".exe" } return name } diff --git a/pkg/installation/move.go b/pkg/installation/move.go index 072992f0..8021f2b6 100644 --- a/pkg/installation/move.go +++ b/pkg/installation/move.go @@ -63,7 +63,7 @@ func findMoveTargets(fromDir, toDir string, fo index.FileOperation) ([]move, err return nil, errors.Errorf("no files in the plugin archive matched the glob pattern=%s", fo.From) } - var moves []move + moves := make([]move, 0, len(gl)) for _, v := range gl { newPath := filepath.Join(newDir, filepath.Base(filepath.FromSlash(v))) // Check secure path diff --git a/pkg/installation/upgrade.go b/pkg/installation/upgrade.go index 7b8f7003..31f29302 100644 --- a/pkg/installation/upgrade.go +++ b/pkg/installation/upgrade.go @@ -84,7 +84,7 @@ func removePluginVersionFromFS(p environment.Paths, plugin index.Plugin, newVers return errors.Wrap(err, "failed to find current krew version") } glog.V(1).Infof("Detected running krew version=%s", executedKrewVersion) - return handleKrewRemove(p, plugin, newVersion, oldVersion, executedKrewVersion) + return handleKrewRemove(p, plugin, newVersion, executedKrewVersion) } glog.V(1).Infof("Remove old plugin installation under %q", p.PluginVersionInstallPath(plugin.Name, oldVersion)) @@ -92,7 +92,7 @@ func removePluginVersionFromFS(p environment.Paths, plugin index.Plugin, newVers } // handleKrewRemove will remove and unlink old krew versions. -func handleKrewRemove(p environment.Paths, plugin index.Plugin, newVersion, oldVersion, currentKrewVersion string) error { +func handleKrewRemove(p environment.Paths, plugin index.Plugin, newVersion, currentKrewVersion string) error { dir, err := ioutil.ReadDir(p.PluginInstallPath(plugin.Name)) if err != nil { return errors.Wrap(err, "can't read plugin dir") diff --git a/pkg/installation/util_test.go b/pkg/installation/util_test.go index c6cdd994..1ed535b8 100644 --- a/pkg/installation/util_test.go +++ b/pkg/installation/util_test.go @@ -22,8 +22,7 @@ import ( "testing" "sigs.k8s.io/krew/pkg/index" - - "k8s.io/apimachinery/pkg/apis/meta/v1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) func Test_osArch_default(t *testing.T) { diff --git a/pkg/version/version.go b/pkg/version/version.go index 74fd509c..60294ead 100644 --- a/pkg/version/version.go +++ b/pkg/version/version.go @@ -1,6 +1,8 @@ // Package version contains the version information of the krew binary. package version +const unknown = "unknown" + var ( // gitCommit contains the git commit idenifier. gitCommit string @@ -13,7 +15,7 @@ var ( // default "unknown" value. func GitCommit() string { if gitCommit == "" { - return "unknown" + return unknown } return gitCommit } @@ -22,7 +24,7 @@ func GitCommit() string { // default "unknown" value. func GitTag() string { if gitTag == "" { - return "unknown" + return unknown } return gitTag } diff --git a/pkg/version/version_test.go b/pkg/version/version_test.go index 67896ba4..861cd22c 100644 --- a/pkg/version/version_test.go +++ b/pkg/version/version_test.go @@ -2,17 +2,19 @@ package version import "testing" +const commitSha = "abcdef" + func TestGitCommit(t *testing.T) { orig := gitCommit defer func() { gitCommit = orig }() gitCommit = "" - if v := GitCommit(); v != "unknown" { + if v := GitCommit(); v != unknown { t.Errorf("empty gitCommit, expected=\"unknown\" got=%q", v) } - gitCommit = "abcdef" - if v := GitCommit(); v != "abcdef" { + gitCommit = commitSha + if v := GitCommit(); v != commitSha { t.Errorf("empty gitCommit, expected=\"abcdef\" got=%q", v) } } @@ -22,12 +24,12 @@ func TestGitTag(t *testing.T) { defer func() { gitTag = orig }() gitTag = "" - if v := GitTag(); v != "unknown" { + if v := GitTag(); v != unknown { t.Errorf("empty gitTag, expected=\"unknown\" got=%q", v) } - gitTag = "abcdef" - if v := GitTag(); v != "abcdef" { + gitTag = commitSha + if v := GitTag(); v != commitSha { t.Errorf("empty gitTag, expected=\"abcdef\" got=%q", v) } }