Skip to content

Commit

Permalink
Enable unparam linter and fix issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleg Atamanenko committed Jun 18, 2018
1 parent 9fc2463 commit f557841
Show file tree
Hide file tree
Showing 18 changed files with 57 additions and 64 deletions.
1 change: 1 addition & 0 deletions bin/pre-commit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ function testGoMetalinter {
--enable=goimports \
--enable=varcheck \
--enable=goconst \
--enable=unparam \
--enable=ineffassign \
--enable=nakedret \
--enable=interfacer \
Expand Down
7 changes: 3 additions & 4 deletions pkg/commands/addpatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package commands
import (
"errors"
"fmt"
"io"

"github.com/spf13/cobra"

Expand All @@ -32,7 +31,7 @@ type addPatchOptions struct {
}

// newCmdAddPatch adds the name of a file containing a patch to the kustomization file.
func newCmdAddPatch(out, errOut io.Writer, fsys fs.FileSystem) *cobra.Command {
func newCmdAddPatch(fsys fs.FileSystem) *cobra.Command {
var o addPatchOptions

cmd := &cobra.Command{
Expand All @@ -49,7 +48,7 @@ func newCmdAddPatch(out, errOut io.Writer, fsys fs.FileSystem) *cobra.Command {
if err != nil {
return err
}
return o.RunAddPatch(out, errOut, fsys)
return o.RunAddPatch(fsys)
},
}
return cmd
Expand All @@ -70,7 +69,7 @@ func (o *addPatchOptions) Complete(cmd *cobra.Command, args []string) error {
}

// RunAddPatch runs addPatch command (do real work).
func (o *addPatchOptions) RunAddPatch(out, errOut io.Writer, fsys fs.FileSystem) error {
func (o *addPatchOptions) RunAddPatch(fsys fs.FileSystem) error {
_, err := fsys.Stat(o.patchFilePath)
if err != nil {
return err
Expand Down
11 changes: 3 additions & 8 deletions pkg/commands/addpatch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ limitations under the License.
package commands

import (
"bytes"
"os"
"testing"

"strings"
Expand All @@ -36,12 +34,11 @@ sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
)

func TestAddPatchHappyPath(t *testing.T) {
buf := bytes.NewBuffer([]byte{})
fakeFS := fs.MakeFakeFS()
fakeFS.WriteFile(patchFileName, []byte(patchFileContent))
fakeFS.WriteFile(constants.KustomizationFileName, []byte(kustomizationContent))

cmd := newCmdAddPatch(buf, os.Stderr, fakeFS)
cmd := newCmdAddPatch(fakeFS)
args := []string{patchFileName}
err := cmd.RunE(cmd, args)
if err != nil {
Expand All @@ -57,12 +54,11 @@ func TestAddPatchHappyPath(t *testing.T) {
}

func TestAddPatchAlreadyThere(t *testing.T) {
buf := bytes.NewBuffer([]byte{})
fakeFS := fs.MakeFakeFS()
fakeFS.WriteFile(patchFileName, []byte(patchFileContent))
fakeFS.WriteFile(constants.KustomizationFileName, []byte(kustomizationContent))

cmd := newCmdAddPatch(buf, os.Stderr, fakeFS)
cmd := newCmdAddPatch(fakeFS)
args := []string{patchFileName}
err := cmd.RunE(cmd, args)
if err != nil {
Expand All @@ -80,10 +76,9 @@ func TestAddPatchAlreadyThere(t *testing.T) {
}

func TestAddPatchNoArgs(t *testing.T) {
buf := bytes.NewBuffer([]byte{})
fakeFS := fs.MakeFakeFS()

cmd := newCmdAddPatch(buf, os.Stderr, fakeFS)
cmd := newCmdAddPatch(fakeFS)
err := cmd.Execute()
if err == nil {
t.Errorf("expected error: %v", err)
Expand Down
7 changes: 3 additions & 4 deletions pkg/commands/addresource.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package commands
import (
"errors"
"fmt"
"io"

"github.com/spf13/cobra"

Expand All @@ -32,7 +31,7 @@ type addResourceOptions struct {
}

// newCmdAddResource adds the name of a file containing a resource to the kustomization file.
func newCmdAddResource(out, errOut io.Writer, fsys fs.FileSystem) *cobra.Command {
func newCmdAddResource(fsys fs.FileSystem) *cobra.Command {
var o addResourceOptions

cmd := &cobra.Command{
Expand All @@ -49,7 +48,7 @@ func newCmdAddResource(out, errOut io.Writer, fsys fs.FileSystem) *cobra.Command
if err != nil {
return err
}
return o.RunAddResource(out, errOut, fsys)
return o.RunAddResource(fsys)
},
}
return cmd
Expand All @@ -70,7 +69,7 @@ func (o *addResourceOptions) Complete(cmd *cobra.Command, args []string) error {
}

// RunAddResource runs addResource command (do real work).
func (o *addResourceOptions) RunAddResource(out, errOut io.Writer, fsys fs.FileSystem) error {
func (o *addResourceOptions) RunAddResource(fsys fs.FileSystem) error {
_, err := fsys.Stat(o.resourceFilePath)
if err != nil {
return err
Expand Down
11 changes: 3 additions & 8 deletions pkg/commands/addresource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ limitations under the License.
package commands

import (
"bytes"
"os"
"testing"

"strings"
Expand Down Expand Up @@ -52,12 +50,11 @@ secretGenerator: []
)

func TestAddResourceHappyPath(t *testing.T) {
buf := bytes.NewBuffer([]byte{})
fakeFS := fs.MakeFakeFS()
fakeFS.WriteFile(resourceFileName, []byte(resourceFileContent))
fakeFS.WriteFile(constants.KustomizationFileName, []byte(kustomizationContent))

cmd := newCmdAddResource(buf, os.Stderr, fakeFS)
cmd := newCmdAddResource(fakeFS)
args := []string{resourceFileName}
err := cmd.RunE(cmd, args)
if err != nil {
Expand All @@ -73,12 +70,11 @@ func TestAddResourceHappyPath(t *testing.T) {
}

func TestAddResourceAlreadyThere(t *testing.T) {
buf := bytes.NewBuffer([]byte{})
fakeFS := fs.MakeFakeFS()
fakeFS.WriteFile(resourceFileName, []byte(resourceFileContent))
fakeFS.WriteFile(constants.KustomizationFileName, []byte(kustomizationContent))

cmd := newCmdAddResource(buf, os.Stderr, fakeFS)
cmd := newCmdAddResource(fakeFS)
args := []string{resourceFileName}
err := cmd.RunE(cmd, args)
if err != nil {
Expand All @@ -96,10 +92,9 @@ func TestAddResourceAlreadyThere(t *testing.T) {
}

func TestAddResourceNoArgs(t *testing.T) {
buf := bytes.NewBuffer([]byte{})
fakeFS := fs.MakeFakeFS()

cmd := newCmdAddResource(buf, os.Stderr, fakeFS)
cmd := newCmdAddResource(fakeFS)
err := cmd.Execute()
if err == nil {
t.Errorf("expected error: %v", err)
Expand Down
6 changes: 3 additions & 3 deletions pkg/commands/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type buildOptions struct {
}

// newCmdBuild creates a new build command.
func newCmdBuild(out, errOut io.Writer, fs fs.FileSystem) *cobra.Command {
func newCmdBuild(out io.Writer, fs fs.FileSystem) *cobra.Command {
var o buildOptions

cmd := &cobra.Command{
Expand All @@ -48,7 +48,7 @@ func newCmdBuild(out, errOut io.Writer, fs fs.FileSystem) *cobra.Command {
if err != nil {
return err
}
return o.RunBuild(out, errOut, fs)
return o.RunBuild(out, fs)
},
}
return cmd
Expand All @@ -68,7 +68,7 @@ func (o *buildOptions) Validate(args []string) error {
}

// RunBuild runs build command.
func (o *buildOptions) RunBuild(out, errOut io.Writer, fs fs.FileSystem) error {
func (o *buildOptions) RunBuild(out io.Writer, fs fs.FileSystem) error {
l := loader.Init([]loader.SchemeLoader{loader.NewFileLoader(fs)})

absPath, err := filepath.Abs(o.kustomizationPath)
Expand Down
2 changes: 1 addition & 1 deletion pkg/commands/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func runBuildTestCase(t *testing.T, testcaseName string, updateKustomizeExpected
kustomizationPath: testcase.Filename,
}
buf := bytes.NewBuffer([]byte{})
err = ops.RunBuild(buf, os.Stderr, fs)
err = ops.RunBuild(buf, fs)
switch {
case err != nil && len(testcase.ExpectedError) == 0:
t.Errorf("unexpected error: %v", err)
Expand Down
24 changes: 12 additions & 12 deletions pkg/commands/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package commands

import (
"flag"
"io"
"os"

"github.com/kubernetes-sigs/kustomize/pkg/fs"
Expand All @@ -42,9 +41,10 @@ See https://github.com/kubernetes-sigs/kustomize
}

c.AddCommand(
newCmdBuild(stdOut, stdErr, fsys),
// TODO: Make consistent API for newCmd* functions.
newCmdBuild(stdOut, fsys),
newCmdDiff(stdOut, stdErr, fsys),
newCmdEdit(stdOut, stdErr, fsys),
newCmdEdit(fsys),
newCmdVersion(stdOut),
)
c.PersistentFlags().AddGoFlagSet(flag.CommandLine)
Expand All @@ -56,7 +56,7 @@ See https://github.com/kubernetes-sigs/kustomize
}

// newCmdEdit returns an instance of 'edit' subcommand.
func newCmdEdit(stdOut, stdErr io.Writer, fsys fs.FileSystem) *cobra.Command {
func newCmdEdit(fsys fs.FileSystem) *cobra.Command {
c := &cobra.Command{
Use: "edit",
Short: "Edits a kustomization file",
Expand All @@ -71,14 +71,14 @@ func newCmdEdit(stdOut, stdErr io.Writer, fsys fs.FileSystem) *cobra.Command {
Args: cobra.MinimumNArgs(1),
}
c.AddCommand(
newCmdAdd(stdOut, stdErr, fsys),
newCmdSet(stdOut, stdErr, fsys),
newCmdAdd(fsys),
newCmdSet(fsys),
)
return c
}

// newAddCommand returns an instance of 'add' subcommand.
func newCmdAdd(stdOut, stdErr io.Writer, fsys fs.FileSystem) *cobra.Command {
func newCmdAdd(fsys fs.FileSystem) *cobra.Command {
c := &cobra.Command{
Use: "add",
Short: "Adds configmap/resource/patch to the kustomization file.",
Expand All @@ -96,15 +96,15 @@ func newCmdAdd(stdOut, stdErr io.Writer, fsys fs.FileSystem) *cobra.Command {
Args: cobra.MinimumNArgs(1),
}
c.AddCommand(
newCmdAddResource(stdOut, stdErr, fsys),
newCmdAddPatch(stdOut, stdErr, fsys),
newCmdAddConfigMap(stdErr, fsys),
newCmdAddResource(fsys),
newCmdAddPatch(fsys),
newCmdAddConfigMap(fsys),
)
return c
}

// newSetCommand returns an instance of 'set' subcommand.
func newCmdSet(stdOut, stdErr io.Writer, fsys fs.FileSystem) *cobra.Command {
func newCmdSet(fsys fs.FileSystem) *cobra.Command {
c := &cobra.Command{
Use: "set",
Short: "Sets the value of different fields in kustomization file.",
Expand All @@ -117,7 +117,7 @@ func newCmdSet(stdOut, stdErr io.Writer, fsys fs.FileSystem) *cobra.Command {
}

c.AddCommand(
newCmdSetNamePrefix(stdOut, stdErr, fsys),
newCmdSetNamePrefix(fsys),
)
return c
}
3 changes: 1 addition & 2 deletions pkg/commands/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package commands

import (
"fmt"
"io"

"github.com/spf13/cobra"

Expand All @@ -28,7 +27,7 @@ import (
"github.com/kubernetes-sigs/kustomize/pkg/types"
)

func newCmdAddConfigMap(errOut io.Writer, fsys fs.FileSystem) *cobra.Command {
func newCmdAddConfigMap(fsys fs.FileSystem) *cobra.Command {
var config dataConfig
cmd := &cobra.Command{
Use: "configmap NAME [--from-file=[key=]source] [--from-literal=key1=value1]",
Expand Down
2 changes: 1 addition & 1 deletion pkg/commands/configmap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
)

func TestNewAddConfigMapIsNotNil(t *testing.T) {
if newCmdAddConfigMap(nil, fs.MakeFakeFS()) == nil {
if newCmdAddConfigMap(fs.MakeFakeFS()) == nil {
t.Fatal("newCmdAddConfigMap shouldn't be nil")
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/commands/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func newCmdDiff(out, errOut io.Writer, fs fs.FileSystem) *cobra.Command {
Use: "diff [path]",
Short: "diff between customized resources and uncustomized resources",
RunE: func(cmd *cobra.Command, args []string) error {
err := o.Validate(cmd, args)
err := o.Validate(args)
if err != nil {
return err
}
Expand All @@ -53,7 +53,7 @@ func newCmdDiff(out, errOut io.Writer, fs fs.FileSystem) *cobra.Command {
}

// Validate validates diff command.
func (o *diffOptions) Validate(cmd *cobra.Command, args []string) error {
func (o *diffOptions) Validate(args []string) error {
if len(args) > 1 {
return errors.New("specify one path to " + constants.KustomizationFileName)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/commands/kustomizationfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type kustomizationFile struct {
fsys fs.FileSystem
}

func newKustomizationFile(mPath string, fsys fs.FileSystem) (*kustomizationFile, error) {
func newKustomizationFile(mPath string, fsys fs.FileSystem) (*kustomizationFile, error) { // nolint
mf := &kustomizationFile{path: mPath, fsys: fsys}
err := mf.validate()
if err != nil {
Expand Down
7 changes: 3 additions & 4 deletions pkg/commands/set_name_prefix.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package commands

import (
"errors"
"io"

"github.com/spf13/cobra"

Expand All @@ -31,7 +30,7 @@ type setNamePrefixOptions struct {
}

// newCmdSetNamePrefix sets the value of the namePrefix field in the kustomization.
func newCmdSetNamePrefix(out, errOut io.Writer, fsys fs.FileSystem) *cobra.Command {
func newCmdSetNamePrefix(fsys fs.FileSystem) *cobra.Command {
var o setNamePrefixOptions

cmd := &cobra.Command{
Expand All @@ -52,7 +51,7 @@ and overwrite the value with "acme-" if the field does exist.
if err != nil {
return err
}
return o.RunSetNamePrefix(out, errOut, fsys)
return o.RunSetNamePrefix(fsys)
},
}
return cmd
Expand All @@ -74,7 +73,7 @@ func (o *setNamePrefixOptions) Complete(cmd *cobra.Command, args []string) error
}

// RunSetNamePrefix runs setNamePrefix command (does real work).
func (o *setNamePrefixOptions) RunSetNamePrefix(out, errOut io.Writer, fsys fs.FileSystem) error {
func (o *setNamePrefixOptions) RunSetNamePrefix(fsys fs.FileSystem) error {
mf, err := newKustomizationFile(constants.KustomizationFileName, fsys)
if err != nil {
return err
Expand Down
Loading

0 comments on commit f557841

Please sign in to comment.