Update gometalinter

The update includes bug fixes in gometalinter and updates to linters, which
discovered more linter problems.

Signed-off-by: Daniel Nephin <dnephin@docker.com>
master
Daniel Nephin 2017-09-26 12:33:35 -04:00
parent 0856c20e04
commit d956386b2d
13 changed files with 41 additions and 21 deletions

View File

@ -185,6 +185,7 @@ func setRawTerminal(streams command.Streams) error {
return streams.Out().SetRawTerminal()
}
// nolint: unparam
func restoreTerminal(streams command.Streams, in io.Closer) error {
streams.In().RestoreTerminal()
streams.Out().RestoreTerminal()

View File

@ -43,6 +43,7 @@ func TestValidateAttach(t *testing.T) {
}
}
// nolint: unparam
func parseRun(args []string) (*container.Config, *container.HostConfig, *networktypes.NetworkingConfig, error) {
flags := pflag.NewFlagSet("run", pflag.ContinueOnError)
flags.SetOutput(ioutil.Discard)

View File

@ -12,6 +12,7 @@ import (
"github.com/docker/notary/passphrase"
"github.com/docker/notary/trustpinning"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func unsetENV() {
@ -67,6 +68,7 @@ func TestAddTargetToAllSignableRolesError(t *testing.T) {
defer os.RemoveAll(tmpDir)
notaryRepo, err := client.NewFileCachedRepository(tmpDir, "gun", "https://localhost", nil, passphrase.ConstantRetriever("password"), trustpinning.TrustPinConfig{})
require.NoError(t, err)
target := client.Target{}
err = AddTargetToAllSignableRoles(notaryRepo, &target)
assert.EqualError(t, err, "client is offline")

View File

@ -104,13 +104,12 @@ func checkDaemonIsSwarmManager(ctx context.Context, dockerCli command.Cli) error
}
// pruneServices removes services that are no longer referenced in the source
func pruneServices(ctx context.Context, dockerCli command.Cli, namespace convert.Namespace, services map[string]struct{}) bool {
func pruneServices(ctx context.Context, dockerCli command.Cli, namespace convert.Namespace, services map[string]struct{}) {
client := dockerCli.Client()
oldServices, err := getServices(ctx, client, namespace.Name())
if err != nil {
fmt.Fprintf(dockerCli.Err(), "Failed to list services: %s", err)
return true
}
pruneServices := []swarm.Service{}
@ -119,5 +118,5 @@ func pruneServices(ctx context.Context, dockerCli command.Cli, namespace convert
pruneServices = append(pruneServices, service)
}
}
return removeServices(ctx, dockerCli, pruneServices)
removeServices(ctx, dockerCli, pruneServices)
}

View File

@ -59,6 +59,7 @@ func TestStackPsEmptyStack(t *testing.T) {
})
cmd := newPsCommand(fakeCli)
cmd.SetArgs([]string{"foo"})
cmd.SetOutput(ioutil.Discard)
assert.Error(t, cmd.Execute())
assert.EqualError(t, cmd.Execute(), "nothing found in stack: foo")

View File

@ -15,24 +15,20 @@ import (
"golang.org/x/net/context"
)
type unlockOptions struct{}
func newUnlockCommand(dockerCli command.Cli) *cobra.Command {
opts := unlockOptions{}
cmd := &cobra.Command{
Use: "unlock",
Short: "Unlock swarm",
Args: cli.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
return runUnlock(dockerCli, opts)
return runUnlock(dockerCli)
},
}
return cmd
}
func runUnlock(dockerCli command.Cli, opts unlockOptions) error {
func runUnlock(dockerCli command.Cli) error {
client := dockerCli.Client()
ctx := context.Background()

View File

@ -11,6 +11,7 @@ import (
"github.com/docker/notary/passphrase"
"github.com/docker/notary/trustpinning"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestTrustRevokeCommandErrors(t *testing.T) {
@ -140,6 +141,7 @@ func TestGetSignableRolesForTargetAndRemoveError(t *testing.T) {
defer os.RemoveAll(tmpDir)
notaryRepo, err := client.NewFileCachedRepository(tmpDir, "gun", "https://localhost", nil, passphrase.ConstantRetriever("password"), trustpinning.TrustPinConfig{})
require.NoError(t, err)
target := client.Target{}
err = getSignableRolesForTargetAndRemove(target, notaryRepo)
assert.EqualError(t, err, "client is offline")

View File

@ -17,6 +17,7 @@ import (
"github.com/docker/notary/trustpinning"
"github.com/docker/notary/tuf/data"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
const passwd = "password"
@ -151,6 +152,7 @@ func TestAddStageSigners(t *testing.T) {
NewThreshold: notary.MinThreshold,
AddKeys: data.KeyList([]data.PublicKey{userKey}),
})
require.NoError(t, err)
expectedChange := changelist.NewTUFChange(
changelist.ActionCreate,
userRole,
@ -165,6 +167,7 @@ func TestAddStageSigners(t *testing.T) {
expectedJSON, err = json.Marshal(&changelist.TUFDelegation{
AddPaths: []string{""},
})
require.NoError(t, err)
expectedChange = changelist.NewTUFChange(
changelist.ActionCreate,
userRole,
@ -182,6 +185,7 @@ func TestAddStageSigners(t *testing.T) {
NewThreshold: notary.MinThreshold,
AddKeys: data.KeyList([]data.PublicKey{userKey}),
})
require.NoError(t, err)
expectedChange = changelist.NewTUFChange(
changelist.ActionCreate,
releasesRole,
@ -196,6 +200,7 @@ func TestAddStageSigners(t *testing.T) {
expectedJSON, err = json.Marshal(&changelist.TUFDelegation{
AddPaths: []string{""},
})
require.NoError(t, err)
expectedChange = changelist.NewTUFChange(
changelist.ActionCreate,
releasesRole,
@ -268,18 +273,24 @@ func TestPrettyPrintExistingSignatureInfo(t *testing.T) {
assert.Contains(t, fakeCli.OutBuffer().String(), "Existing signatures for tag tagName digest abc123 from:\nAlice, Bob, Carol")
}
func TestChangeList(t *testing.T) {
func TestSignCommandChangeListIsCleanedOnError(t *testing.T) {
tmpDir, err := ioutil.TempDir("", "docker-sign-test-")
assert.NoError(t, err)
defer os.RemoveAll(tmpDir)
config.SetDir(tmpDir)
cmd := newSignCommand(
test.NewFakeCli(&fakeClient{}))
cli := test.NewFakeCli(&fakeClient{})
cli.SetNotaryClient(getLoadedNotaryRepository)
cmd := newSignCommand(cli)
cmd.SetArgs([]string{"ubuntu:latest"})
cmd.SetOutput(ioutil.Discard)
err = cmd.Execute()
require.Error(t, err)
notaryRepo, err := client.NewFileCachedRepository(tmpDir, "docker.io/library/ubuntu", "https://localhost", nil, passphrase.ConstantRetriever(passwd), trustpinning.TrustPinConfig{})
assert.NoError(t, err)
cl, err := notaryRepo.GetChangelist()
require.NoError(t, err)
assert.Equal(t, len(cl.List()), 0)
}

View File

@ -113,7 +113,9 @@ func lookupTrustInfo(cli command.Cli, remote string) error {
// If we do not have additional signers, do not display
if len(signerRoleToKeyIDs) > 0 {
fmt.Fprintf(cli.Out(), "\nList of signers and their keys for %s:\n\n", strings.Split(remote, ":")[0])
printSignerInfo(cli.Out(), signerRoleToKeyIDs)
if err := printSignerInfo(cli.Out(), signerRoleToKeyIDs); err != nil {
return err
}
}
// This will always have the root and targets information

View File

@ -11,6 +11,7 @@ import (
"github.com/docker/notary/trustpinning"
digest "github.com/opencontainers/go-digest"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestGetTag(t *testing.T) {
@ -53,6 +54,7 @@ func TestGetSignableRolesError(t *testing.T) {
defer os.RemoveAll(tmpDir)
notaryRepo, err := client.NewFileCachedRepository(tmpDir, "gun", "https://localhost", nil, passphrase.ConstantRetriever("password"), trustpinning.TrustPinConfig{})
require.NoError(t, err)
target := client.Target{}
_, err = GetSignableRoles(notaryRepo, &target)
assert.EqualError(t, err, "client is offline")

View File

@ -2,7 +2,7 @@ FROM golang:1.8.3-alpine
RUN apk add -U git
ARG GOMETALINTER_SHA=4306381615a2ba2a207f8fcea02c08c6b2b0803f
ARG GOMETALINTER_SHA=8eca55135021737bbc65ed68b548b3336853274c
RUN go get -d github.com/alecthomas/gometalinter && \
cd /go/src/github.com/alecthomas/gometalinter && \
git checkout -q "$GOMETALINTER_SHA" && \

View File

@ -10,7 +10,7 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"gopkg.in/yaml.v2"
yaml "gopkg.in/yaml.v2"
)
type cmdOption struct {
@ -46,18 +46,17 @@ type cmdDoc struct {
// GenYamlTree creates yaml structured ref files
func GenYamlTree(cmd *cobra.Command, dir string) error {
identity := func(s string) string { return s }
emptyStr := func(s string) string { return "" }
return GenYamlTreeCustom(cmd, dir, emptyStr, identity)
return GenYamlTreeCustom(cmd, dir, emptyStr)
}
// GenYamlTreeCustom creates yaml structured ref files
func GenYamlTreeCustom(cmd *cobra.Command, dir string, filePrepender, linkHandler func(string) string) error {
func GenYamlTreeCustom(cmd *cobra.Command, dir string, filePrepender func(string) string) error {
for _, c := range cmd.Commands() {
if !c.IsAvailableCommand() || c.IsHelpCommand() {
continue
}
if err := GenYamlTreeCustom(c, dir, filePrepender, linkHandler); err != nil {
if err := GenYamlTreeCustom(c, dir, filePrepender); err != nil {
return err
}
}

View File

@ -1,8 +1,12 @@
{
"Vendor": true,
"Deadline": "2m",
"Sort": ["linter", "severity", "path"],
"Exclude": ["cli/compose/schema/bindata.go"],
"Sort": ["linter", "severity", "path", "line"],
"Exclude": [
"cli/compose/schema/bindata.go",
"parameter .* always receives"
],
"EnableGC": true,
"DisableAll": true,
"Enable": [