Skip to content

Commit

Permalink
Fix lint errors (kubernetes-sigs#16)
Browse files Browse the repository at this point in the history
This fixes lint errors mainly with inserting TODOS.
  • Loading branch information
lbb authored and ahmetb committed Jul 28, 2018
1 parent 5a75445 commit 08412be
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 25 deletions.
2 changes: 1 addition & 1 deletion cmd/krew/cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ All plugins will be downloaded and made available to: "kubectl plugin <name>"`,
for _, plugin := range install {
glog.V(2).Infof("Installing plugin: %s\n", plugin.Name)
err := installation.Install(paths, plugin, *forceHEAD)
if err == installation.IsAlreadyInstalledErr {
if err == installation.ErrIsAlreadyInstalled {
glog.Warningf("Skipping plugin %s, it is already installed", plugin.Name)
continue
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/krew/cmd/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ kubectl plugin upgrade foo bar"`,

glog.V(2).Infof("Upgrading plugin: %s\n", plugin.Name)
err = installation.Upgrade(paths, plugin, krewExecutedVersion)
if ignoreUpgraded && err == installation.IsAlreadyUpgradedErr {
if ignoreUpgraded && err == installation.ErrIsAlreadyUpgraded {
fmt.Fprintf(os.Stderr, "Skipping plugin %s, it is already on the newest version\n", plugin.Name)
continue
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/index/indexscanner/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ import (
)

// LoadPluginListFromFS will parse and retrieve all plugin files.
func LoadPluginListFromFS(indexDir string) (index.IndexList, error) {
var indexList index.IndexList
func LoadPluginListFromFS(indexDir string) (index.PluginList, error) {
var indexList index.PluginList
indexDir, err := filepath.EvalSymlinks(indexDir)
if err != nil {
return indexList, err
Expand Down
6 changes: 5 additions & 1 deletion pkg/index/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type Plugin struct {
Spec PluginSpec `json:"spec"`
}

// PluginSpec TODO(lbb)
type PluginSpec struct {
Version string `json:"version,omitempty"`
ShortDescription string `json:"shortDescription,omitempty"`
Expand All @@ -36,6 +37,7 @@ type PluginSpec struct {
Platforms []Platform `json:"platforms,omitempty"`
}

// Platform TODO(lbb)
type Platform struct {
Head string `json:"head,omitempty"`
URI string `json:"uri,omitempty"`
Expand All @@ -45,12 +47,14 @@ type Platform struct {
Files []FileOperation `json:"files"`
}

// FileOperation TODO(lbb)
type FileOperation struct {
From string `json:"from,omitempty"`
To string `json:"to,omitempty"`
}

type IndexList struct {
// PluginList TODO(lbb)
type PluginList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`

Expand Down
2 changes: 2 additions & 0 deletions pkg/index/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func IsSafePluginName(name string) bool {
return true
}

// Validate TODO(lbb)
func (p Plugin) Validate(name string) error {
if !IsSafePluginName(name) {
return fmt.Errorf("the plugin name %q is not allowed, must match %q", name, safePluginRegexp.String())
Expand All @@ -60,6 +61,7 @@ func (p Plugin) Validate(name string) error {
return nil
}

// Validate TODO(lbb)
func (p Platform) Validate() error {
if (p.Sha256 != "") != (p.URI != "") {
return fmt.Errorf("can't get version URI and sha have both to be set or unset")
Expand Down
11 changes: 6 additions & 5 deletions pkg/installation/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ import (
"github.com/golang/glog"
)

// Plugin Lifecycle Errors
var (
IsAlreadyInstalledErr = fmt.Errorf("can't install, the newest version is already installed")
IsNotInstalledErr = fmt.Errorf("plugin is not installed")
IsAlreadyUpgradedErr = fmt.Errorf("can't upgrade, the newest version is already installed")
ErrIsAlreadyInstalled = fmt.Errorf("can't install, the newest version is already installed")
ErrIsNotInstalled = fmt.Errorf("plugin is not installed")
ErrIsAlreadyUpgraded = fmt.Errorf("can't upgrade, the newest version is already installed")
)

const (
Expand Down Expand Up @@ -67,7 +68,7 @@ func Install(p environment.KrewPaths, plugin index.Plugin, forceHEAD bool) error
return err
}
if ok {
return IsAlreadyInstalledErr
return ErrIsAlreadyInstalled
}

glog.V(1).Infof("Finding download target for plugin %s", plugin.Name)
Expand All @@ -89,7 +90,7 @@ func Remove(p environment.KrewPaths, name string) error {
return fmt.Errorf("can't remove plugin, err: %v", err)
}
if !installed {
return IsNotInstalledErr
return ErrIsNotInstalled
}
glog.V(1).Infof("Deleting plugin version %s", version)
glog.V(3).Infof("Deleting path %q", filepath.Join(p.Install, name))
Expand Down
2 changes: 1 addition & 1 deletion pkg/installation/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func Upgrade(p environment.KrewPaths, plugin index.Plugin, currentKrewVersion st
// Check allowed installation
newVersion, uri, fos, err := getDownloadTarget(plugin, oldVersion == headVersion)
if oldVersion == newVersion && oldVersion != headVersion {
return IsAlreadyUpgradedErr
return ErrIsAlreadyUpgraded
}
if err != nil {
return fmt.Errorf("failed to get the current download target, err: %v", err)
Expand Down
1 change: 1 addition & 0 deletions pkg/installation/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"k8s.io/apimachinery/pkg/labels"
)

// GetMatchingPlatform TODO(lbb)
func GetMatchingPlatform(i index.Plugin) (index.Platform, bool, error) {
return matchPlatformToSystemEnvs(i, runtime.GOOS, runtime.GOARCH)
}
Expand Down
28 changes: 14 additions & 14 deletions pkg/installation/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func Test_getPluginVersion(t *testing.T) {
name string
args args
wantVersion string
wantUri string
wantURI string
wantErr bool
}{
{
Expand All @@ -129,7 +129,7 @@ func Test_getPluginVersion(t *testing.T) {
forceHEAD: false,
},
wantVersion: "HEAD",
wantUri: "https://head.git",
wantURI: "https://head.git",
}, {
name: "Get URI default",
args: args{
Expand All @@ -141,7 +141,7 @@ func Test_getPluginVersion(t *testing.T) {
forceHEAD: false,
},
wantVersion: "deadbeef",
wantUri: "https://uri.git",
wantURI: "https://uri.git",
}, {
name: "Get HEAD force",
args: args{
Expand All @@ -153,7 +153,7 @@ func Test_getPluginVersion(t *testing.T) {
forceHEAD: true,
},
wantVersion: "HEAD",
wantUri: "https://head.git",
wantURI: "https://head.git",
}, {
name: "HEAD force fallback",
args: args{
Expand All @@ -166,20 +166,20 @@ func Test_getPluginVersion(t *testing.T) {
},
wantErr: true,
wantVersion: "",
wantUri: "",
wantURI: "",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gotVersion, gotUri, err := getPluginVersion(tt.args.p, tt.args.forceHEAD)
gotVersion, gotURI, err := getPluginVersion(tt.args.p, tt.args.forceHEAD)
if (err != nil) != tt.wantErr {
t.Errorf("getPluginVersion() gotVersion = %v, want %v, got err = %v want err = %v", gotVersion, tt.wantVersion, err, tt.wantErr)
}
if gotVersion != tt.wantVersion {
t.Errorf("getPluginVersion() gotVersion = %v, want %v", gotVersion, tt.wantVersion)
}
if gotUri != tt.wantUri {
t.Errorf("getPluginVersion() gotUri = %v, want %v", gotUri, tt.wantUri)
if gotURI != tt.wantURI {
t.Errorf("getPluginVersion() gotURI = %v, want %v", gotURI, tt.wantURI)
}
})
}
Expand All @@ -205,7 +205,7 @@ func Test_getDownloadTarget(t *testing.T) {
name string
args args
wantVersion string
wantUri string
wantURI string
wantFos []index.FileOperation
wantErr bool
}{
Expand All @@ -230,7 +230,7 @@ func Test_getDownloadTarget(t *testing.T) {
},
},
wantVersion: "HEAD",
wantUri: "https://head.git",
wantURI: "https://head.git",
wantFos: nil,
wantErr: false,
}, {
Expand All @@ -253,23 +253,23 @@ func Test_getDownloadTarget(t *testing.T) {
},
},
wantVersion: "",
wantUri: "",
wantURI: "",
wantFos: nil,
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gotVersion, gotUri, gotFos, err := getDownloadTarget(tt.args.index, tt.args.forceHEAD)
gotVersion, gotURI, gotFos, err := getDownloadTarget(tt.args.index, tt.args.forceHEAD)
if (err != nil) != tt.wantErr {
t.Errorf("getDownloadTarget() error = %v, wantErr %v", err, tt.wantErr)
return
}
if gotVersion != tt.wantVersion {
t.Errorf("getDownloadTarget() gotVersion = %v, want %v", gotVersion, tt.wantVersion)
}
if gotUri != tt.wantUri {
t.Errorf("getDownloadTarget() gotUri = %v, want %v", gotUri, tt.wantUri)
if gotURI != tt.wantURI {
t.Errorf("getDownloadTarget() gotURI = %v, want %v", gotURI, tt.wantURI)
}
if !reflect.DeepEqual(gotFos, tt.wantFos) {
t.Errorf("getDownloadTarget() gotFos = %v, want %v", gotFos, tt.wantFos)
Expand Down

0 comments on commit 08412be

Please sign in to comment.