1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #34551 from dnephin/use-gometalinter

Use gometalinter for linting
This commit is contained in:
Yong Tang 2017-08-19 09:40:47 -07:00 committed by GitHub
commit 4c8cde597d
41 changed files with 93 additions and 202 deletions

View file

@ -115,17 +115,6 @@ RUN curl -fsSL "https://golang.org/dl/go${GO_VERSION}.linux-amd64.tar.gz" \
ENV PATH /go/bin:/usr/local/go/bin:$PATH
ENV GOPATH /go
# Dependency for golint
ENV GO_TOOLS_COMMIT 823804e1ae08dbb14eb807afc7db9993bc9e3cc3
RUN git clone https://github.com/golang/tools.git /go/src/golang.org/x/tools \
&& (cd /go/src/golang.org/x/tools && git checkout -q $GO_TOOLS_COMMIT)
# Grab Go's lint tool
ENV GO_LINT_COMMIT 32a87160691b3c96046c0c678fe57c5bef761456
RUN git clone https://github.com/golang/lint.git /go/src/github.com/golang/lint \
&& (cd /go/src/github.com/golang/lint && git checkout -q $GO_LINT_COMMIT) \
&& go install -v github.com/golang/lint/golint
# Install CRIU for checkpoint/restore support
ENV CRIU_VERSION 2.12.1
# Install dependancy packages specific to criu
@ -215,7 +204,7 @@ RUN ./contrib/download-frozen-image-v2.sh /docker-frozen-images \
# Please edit hack/dockerfile/install-binaries.sh to update them.
COPY hack/dockerfile/binaries-commits /tmp/binaries-commits
COPY hack/dockerfile/install-binaries.sh /tmp/install-binaries.sh
RUN /tmp/install-binaries.sh tomlv vndr runc containerd tini proxy dockercli
RUN /tmp/install-binaries.sh tomlv vndr runc containerd tini proxy dockercli gometalinter
ENV PATH=/usr/local/cli:$PATH
# Activate bash completion and include Docker's completion if mounted with DOCKER_BASH_COMPLETION_PATH

View file

@ -98,17 +98,6 @@ RUN mkdir /usr/src/go && curl -fsSL https://golang.org/dl/go${GO_VERSION}.src.ta
ENV PATH /go/bin:/usr/src/go/bin:$PATH
ENV GOPATH /go
# Dependency for golint
ENV GO_TOOLS_COMMIT 823804e1ae08dbb14eb807afc7db9993bc9e3cc3
RUN git clone https://github.com/golang/tools.git /go/src/golang.org/x/tools \
&& (cd /go/src/golang.org/x/tools && git checkout -q $GO_TOOLS_COMMIT)
# Grab Go's lint tool
ENV GO_LINT_COMMIT 32a87160691b3c96046c0c678fe57c5bef761456
RUN git clone https://github.com/golang/lint.git /go/src/github.com/golang/lint \
&& (cd /go/src/github.com/golang/lint && git checkout -q $GO_LINT_COMMIT) \
&& go install -v github.com/golang/lint/golint
# Only install one version of the registry, because old version which support
# schema1 manifests is not working on ARM64, we should skip integration-cli
# tests for schema1 manifests on ARM64.

View file

@ -81,17 +81,6 @@ ENV GOPATH /go
ENV GOARCH arm
ENV GOARM 7
# Dependency for golint
ENV GO_TOOLS_COMMIT 823804e1ae08dbb14eb807afc7db9993bc9e3cc3
RUN git clone https://github.com/golang/tools.git /go/src/golang.org/x/tools \
&& (cd /go/src/golang.org/x/tools && git checkout -q $GO_TOOLS_COMMIT)
# Grab Go's lint tool
ENV GO_LINT_COMMIT 32a87160691b3c96046c0c678fe57c5bef761456
RUN git clone https://github.com/golang/lint.git /go/src/github.com/golang/lint \
&& (cd /go/src/github.com/golang/lint && git checkout -q $GO_LINT_COMMIT) \
&& go install -v github.com/golang/lint/golint
# Install seccomp: the version shipped upstream is too old
ENV SECCOMP_VERSION 2.3.2
RUN set -x \

View file

@ -94,17 +94,6 @@ RUN curl -fsSL "https://golang.org/dl/go${GO_VERSION}.linux-ppc64le.tar.gz" \
ENV PATH /go/bin:/usr/local/go/bin:$PATH
ENV GOPATH /go
# Dependency for golint
ENV GO_TOOLS_COMMIT 823804e1ae08dbb14eb807afc7db9993bc9e3cc3
RUN git clone https://github.com/golang/tools.git /go/src/golang.org/x/tools \
&& (cd /go/src/golang.org/x/tools && git checkout -q $GO_TOOLS_COMMIT)
# Grab Go's lint tool
ENV GO_LINT_COMMIT 32a87160691b3c96046c0c678fe57c5bef761456
RUN git clone https://github.com/golang/lint.git /go/src/github.com/golang/lint \
&& (cd /go/src/github.com/golang/lint && git checkout -q $GO_LINT_COMMIT) \
&& go install -v github.com/golang/lint/golint
# Install two versions of the registry. The first is an older version that
# only supports schema1 manifests. The second is a newer version that supports
# both. This allows integration-cli tests to cover push/pull with both schema1

View file

@ -87,17 +87,6 @@ RUN curl -fsSL "https://golang.org/dl/go${GO_VERSION}.linux-s390x.tar.gz" \
ENV PATH /go/bin:/usr/local/go/bin:$PATH
ENV GOPATH /go
# Dependency for golint
ENV GO_TOOLS_COMMIT 823804e1ae08dbb14eb807afc7db9993bc9e3cc3
RUN git clone https://github.com/golang/tools.git /go/src/golang.org/x/tools \
&& (cd /go/src/golang.org/x/tools && git checkout -q $GO_TOOLS_COMMIT)
# Grab Go's lint tool
ENV GO_LINT_COMMIT 32a87160691b3c96046c0c678fe57c5bef761456
RUN git clone https://github.com/golang/lint.git /go/src/github.com/golang/lint \
&& (cd /go/src/github.com/golang/lint && git checkout -q $GO_LINT_COMMIT) \
&& go install -v github.com/golang/lint/golint
# Install two versions of the registry. The first is an older version that
# only supports schema1 manifests. The second is a newer version that supports
# both. This allows integration-cli tests to cover push/pull with both schema1

View file

@ -53,6 +53,7 @@ func (v VersionMiddleware) WrapHandler(handler func(ctx context.Context, w http.
w.Header().Set("Server", header)
w.Header().Set("API-Version", v.defaultVersion)
w.Header().Set("OSType", runtime.GOOS)
// nolint: golint
ctx = context.WithValue(ctx, "api-version", apiVersion)
return handler(ctx, w, r, vars)
}

View file

@ -19,7 +19,7 @@ import (
)
var (
errDockerfileNotStringArray = errors.New("When using JSON array syntax, arrays must be comprised of strings only.")
errDockerfileNotStringArray = errors.New("when using JSON array syntax, arrays must be comprised of strings only")
)
const (

View file

@ -453,7 +453,7 @@ func loadDaemonCliConfig(opts *daemonOptions) (*config.Config, error) {
c, err := config.MergeDaemonConfigurations(conf, flags, opts.configFile)
if err != nil {
if flags.Changed("config-file") || !os.IsNotExist(err) {
return nil, fmt.Errorf("unable to configure the Docker daemon with file %s: %v\n", opts.configFile, err)
return nil, fmt.Errorf("unable to configure the Docker daemon with file %s: %v", opts.configFile, err)
}
}
// the merged configuration can be nil if the config file didn't exist.

View file

@ -31,11 +31,11 @@ func (daemon *Daemon) ContainerAttach(prefixOrName string, c *backend.ContainerA
return err
}
if container.IsPaused() {
err := fmt.Errorf("Container %s is paused, unpause the container before attach.", prefixOrName)
err := fmt.Errorf("container %s is paused, unpause the container before attach", prefixOrName)
return stateConflictError{err}
}
if container.IsRestarting() {
err := fmt.Errorf("Container %s is restarting, wait until the container is running.", prefixOrName)
err := fmt.Errorf("container %s is restarting, wait until the container is running", prefixOrName)
return stateConflictError{err}
}

View file

@ -66,7 +66,7 @@ var (
// containerd if none is specified
DefaultRuntimeBinary = "docker-runc"
errSystemNotSupported = errors.New("The Docker daemon is not supported on this platform.")
errSystemNotSupported = errors.New("the Docker daemon is not supported on this platform")
)
type daemonStore struct {

View file

@ -557,13 +557,13 @@ func verifyPlatformContainerSettings(daemon *Daemon, hostConfig *containertypes.
// check for various conflicting options with user namespaces
if daemon.configStore.RemappedRoot != "" && hostConfig.UsernsMode.IsPrivate() {
if hostConfig.Privileged {
return warnings, fmt.Errorf("Privileged mode is incompatible with user namespaces. You must run the container in the host namespace when running privileged mode.")
return warnings, fmt.Errorf("privileged mode is incompatible with user namespaces. You must run the container in the host namespace when running privileged mode")
}
if hostConfig.NetworkMode.IsHost() && !hostConfig.UsernsMode.IsHost() {
return warnings, fmt.Errorf("Cannot share the host's network namespace when user namespaces are enabled")
return warnings, fmt.Errorf("cannot share the host's network namespace when user namespaces are enabled")
}
if hostConfig.PidMode.IsHost() && !hostConfig.UsernsMode.IsHost() {
return warnings, fmt.Errorf("Cannot share the host PID namespace when user namespaces are enabled")
return warnings, fmt.Errorf("cannot share the host PID namespace when user namespaces are enabled")
}
}
if hostConfig.CgroupParent != "" && UsingSystemd(daemon.configStore) {
@ -1125,7 +1125,7 @@ func setupDaemonRoot(config *config.Config, rootDir string, rootIDs idtools.IDPa
break
}
if !idtools.CanAccess(dirPath, rootIDs) {
return fmt.Errorf("A subdirectory in your graphroot path (%s) restricts access to the remapped root uid/gid; please fix by allowing 'o+x' permissions on existing directories.", config.Root)
return fmt.Errorf("a subdirectory in your graphroot path (%s) restricts access to the remapped root uid/gid; please fix by allowing 'o+x' permissions on existing directories", config.Root)
}
}
}

View file

@ -2664,7 +2664,7 @@ func NewDeviceSet(root string, doInit bool, options []string, uidMaps, gidMaps [
devices.metaDataLoopbackSize = size
case "dm.fs":
if val != "ext4" && val != "xfs" {
return nil, fmt.Errorf("devmapper: Unsupported filesystem %s\n", val)
return nil, fmt.Errorf("devmapper: Unsupported filesystem %s", val)
}
devices.filesystem = val
case "dm.mkfsarg":
@ -2786,7 +2786,7 @@ func NewDeviceSet(root string, doInit bool, options []string, uidMaps, gidMaps [
Level: int(level),
})
default:
return nil, fmt.Errorf("devmapper: Unknown option %s\n", key)
return nil, fmt.Errorf("devmapper: Unknown option %s", key)
}
}

View file

@ -121,7 +121,7 @@ func copyDir(srcDir, dstDir string, flags copyFlags) error {
}
default:
return fmt.Errorf("Unknown file type for %s\n", srcPath)
return fmt.Errorf("unknown file type for %s", srcPath)
}
// Everything below is copying metadata from src to dst. All this metadata

View file

@ -101,7 +101,7 @@ func (p *cmdProbe) run(ctx context.Context, d *Daemon, cntr *container.Container
return nil, err
}
if info.ExitCode == nil {
return nil, fmt.Errorf("Healthcheck for container %s has no exit code!", cntr.ID)
return nil, fmt.Errorf("healthcheck for container %s has no exit code", cntr.ID)
}
// Note: Go's json package will handle invalid UTF-8 for us
out := output.String()

View file

@ -162,7 +162,7 @@ func TestCreateError(t *testing.T) {
client: mockClient,
}
mockClient.createLogStreamResult <- &createLogStreamResult{
errorResult: errors.New("Error!"),
errorResult: errors.New("Error"),
}
err := stream.create()
@ -243,7 +243,7 @@ func TestPublishBatchError(t *testing.T) {
sequenceToken: aws.String(sequenceToken),
}
mockClient.putLogEventsResult <- &putLogEventsResult{
errorResult: errors.New("Error!"),
errorResult: errors.New("Error"),
}
events := []wrappedEvent{

View file

@ -203,7 +203,7 @@ func New(info logger.Info) (logger.Logger, error) {
}
gzipCompressionLevel = int(gzipCompressionLevel64)
if gzipCompressionLevel < gzip.DefaultCompression || gzipCompressionLevel > gzip.BestCompression {
err := fmt.Errorf("Not supported level '%s' for %s (supported values between %d and %d).",
err := fmt.Errorf("not supported level '%s' for %s (supported values between %d and %d)",
gzipCompressionLevelStr, splunkGzipCompressionLevelKey, gzip.DefaultCompression, gzip.BestCompression)
return nil, err
}

View file

@ -36,7 +36,7 @@ func (daemon *Daemon) StateChanged(id string, e libcontainerd.StateInfo) error {
case libcontainerd.StateOOM:
// StateOOM is Linux specific and should never be hit on Windows
if runtime.GOOS == "windows" {
return errors.New("Received StateOOM from libcontainerd on Windows. This should never happen.")
return errors.New("received StateOOM from libcontainerd on Windows. This should never happen")
}
daemon.updateHealthMonitor(c)
if err := c.CheckpointTo(daemon.containersReplica); err != nil {

View file

@ -348,6 +348,7 @@ func (daemon *Daemon) createNetwork(create types.NetworkCreateRequest, id string
n, err := c.NewNetwork(driver, create.Name, id, nwOptions...)
if err != nil {
if _, ok := err.(libnetwork.ErrDataStoreNotInitialized); ok {
// nolint: golint
return nil, errors.New("This node is not a swarm manager. Use \"docker swarm init\" or \"docker swarm join\" to connect this node to swarm and try again.")
}
return nil, err

View file

@ -438,7 +438,7 @@ func ensureShared(path string) error {
}
if !sharedMount {
return fmt.Errorf("Path %s is mounted on %s but it is not a shared mount.", path, sourceMount)
return fmt.Errorf("path %s is mounted on %s but it is not a shared mount", path, sourceMount)
}
return nil
}
@ -465,7 +465,7 @@ func ensureSharedOrSlave(path string) error {
}
if !sharedMount && !slaveMount {
return fmt.Errorf("Path %s is mounted on %s but it is not a shared or slave mount.", path, sourceMount)
return fmt.Errorf("path %s is mounted on %s but it is not a shared or slave mount", path, sourceMount)
}
return nil
}

View file

@ -27,7 +27,7 @@ func (daemon *Daemon) ContainerStart(name string, hostConfig *containertypes.Hos
defer container.Unlock()
if container.Paused {
return stateConflictError{errors.New("Cannot start a paused container, try unpause instead.")}
return stateConflictError{errors.New("cannot start a paused container, try unpause instead")}
}
if container.Running {
@ -35,7 +35,7 @@ func (daemon *Daemon) ContainerStart(name string, hostConfig *containertypes.Hos
}
if container.RemovalInProgress || container.Dead {
return stateConflictError{errors.New("Container is marked for removal and cannot be started.")}
return stateConflictError{errors.New("container is marked for removal and cannot be started")}
}
return nil
}
@ -110,7 +110,7 @@ func (daemon *Daemon) containerStart(container *container.Container, checkpoint
}
if container.RemovalInProgress || container.Dead {
return stateConflictError{errors.New("Container is marked for removal and cannot be started.")}
return stateConflictError{errors.New("container is marked for removal and cannot be started")}
}
// if we encounter an error during start we need to ensure that any other

View file

@ -50,7 +50,7 @@ func (daemon *Daemon) update(name string, hostConfig *container.HostConfig) erro
}()
if container.RemovalInProgress || container.Dead {
return errCannotUpdate(container.ID, fmt.Errorf("Container is marked for removal and cannot be \"update\"."))
return errCannotUpdate(container.ID, fmt.Errorf("container is marked for removal and cannot be \"update\""))
}
container.Lock()

View file

@ -908,7 +908,7 @@ func fixManifestLayers(m *schema1.Manifest) error {
m.FSLayers = append(m.FSLayers[:i], m.FSLayers[i+1:]...)
m.History = append(m.History[:i], m.History[i+1:]...)
} else if imgs[i].Parent != imgs[i+1].ID {
return fmt.Errorf("Invalid parent ID. Expected %v, got %v.", imgs[i+1].ID, imgs[i].Parent)
return fmt.Errorf("invalid parent ID. Expected %v, got %v", imgs[i+1].ID, imgs[i].Parent)
}
}

View file

@ -10,6 +10,7 @@ import (
"github.com/docker/distribution/manifest/schema1"
"github.com/docker/distribution/reference"
"github.com/docker/docker/pkg/testutil"
"github.com/opencontainers/go-digest"
)
@ -102,9 +103,8 @@ func TestFixManifestLayersBadParent(t *testing.T) {
},
}
if err := fixManifestLayers(&duplicateLayerManifest); err == nil || !strings.Contains(err.Error(), "Invalid parent ID.") {
t.Fatalf("expected an invalid parent ID error from fixManifestLayers")
}
err := fixManifestLayers(&duplicateLayerManifest)
testutil.ErrorContains(t, err, "invalid parent ID")
}
// TestValidateManifest verifies the validateManifest function

View file

@ -12,3 +12,6 @@ VNDR_COMMIT=9909bb2b8a0b7ea464527b376dc50389c90df587
# CLI
DOCKERCLI_REPO=https://github.com/docker/cli
DOCKERCLI_COMMIT=3dfb8343b139d6342acfd9975d7f1068b5b1c3d3
# Linting
GOMETALINTER_COMMIT=f7b6e55301c9c67035003b7ba7f8a1cde532d338

View file

@ -54,6 +54,19 @@ install_dockercli() {
go build -o /usr/local/bin/docker github.com/docker/cli/cmd/docker
}
install_gometalinter() {
echo "Installing gometalinter version $GOMETALINTER_COMMIT"
go get -d github.com/alecthomas/gometalinter
cd "$GOPATH/src/github.com/alecthomas/gometalinter"
git checkout -q "$GOMETALINTER_COMMIT"
go build -o /usr/local/bin/gometalinter github.com/alecthomas/gometalinter
(
export GOBIN=/usr/local/bin
export GOPATH="$PWD/_linters/"
go install github.com/golang/lint/golint
)
}
for prog in "$@"
do
case $prog in
@ -80,6 +93,10 @@ do
install_containerd
;;
gometalinter)
install_gometalinter
;;
tini)
echo "Install tini version $TINI_COMMIT"
git clone https://github.com/krallin/tini.git "$GOPATH/tini"
@ -114,7 +131,7 @@ do
;;
*)
echo echo "Usage: $0 [tomlv|runc|runc-dynamic|containerd|containerd-dynamic|tini|proxy|proxy-dynamic|vndr|dockercli]"
echo echo "Usage: $0 [tomlv|runc|runc-dynamic|containerd|containerd-dynamic|tini|proxy|proxy-dynamic|vndr|dockercli|gometalinter]"
exit 1
esac

View file

@ -6,14 +6,12 @@ export SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
. $SCRIPTDIR/dco
. $SCRIPTDIR/default-seccomp
. $SCRIPTDIR/gofmt
. $SCRIPTDIR/lint
. $SCRIPTDIR/gometalinter
. $SCRIPTDIR/pkg-imports
. $SCRIPTDIR/swagger
. $SCRIPTDIR/swagger-gen
. $SCRIPTDIR/test-imports
. $SCRIPTDIR/toml
. $SCRIPTDIR/vet
. $SCRIPTDIR/changelog-well-formed
. $SCRIPTDIR/changelog-date-descending
. $SCRIPTDIR/deprecate-integration-cli

View file

@ -1,33 +0,0 @@
#!/usr/bin/env bash
export SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "${SCRIPTDIR}/.validate"
IFS=$'\n'
files=( $(validate_diff --diff-filter=ACMR --name-only -- '*.go' |
grep -v '^vendor/' |
grep -v '\.pb\.go$' || true) )
unset IFS
badFiles=()
for f in "${files[@]}"; do
# we use "git show" here to validate that what's committed is formatted
if [ "$(git show "$VALIDATE_HEAD:$f" | gofmt -s -l)" ]; then
badFiles+=( "$f" )
fi
done
if [ ${#badFiles[@]} -eq 0 ]; then
echo 'Congratulations! All Go source files are properly formatted.'
else
{
echo "These files are not properly gofmt'd:"
for f in "${badFiles[@]}"; do
echo " - $f"
done
echo
echo 'Please reformat the above files using "gofmt -s -w" and commit the result.'
echo
} >&2
false
fi

6
hack/validate/gometalinter Executable file
View file

@ -0,0 +1,6 @@
#!/usr/bin/env bash
set -e -o pipefail
SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
gometalinter --config $SCRIPTDIR/gometalinter.json ./...

View file

@ -0,0 +1,19 @@
{
"Vendor": true,
"Deadline": "2m",
"Sort": ["linter", "severity", "path"],
"Exclude": [
".*\\.pb\\.go",
"dockerversion/version_autogen.go",
"api/types/container/container_.*",
"integration-cli/"
],
"Enable": [
"gofmt",
"golint",
"vet"
],
"LineLength": 200
}

View file

@ -1,31 +0,0 @@
#!/usr/bin/env bash
export SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "${SCRIPTDIR}/.validate"
IFS=$'\n'
files=( $(validate_diff --diff-filter=ACMR --name-only -- '*.go' | grep -v '^vendor/' | grep -v '^api/types/container/' | grep -v '\.pb\.go$' || true) )
unset IFS
errors=()
for f in "${files[@]}"; do
failedLint=$(golint "$f")
if [ "$failedLint" ]; then
errors+=( "$failedLint" )
fi
done
if [ ${#errors[@]} -eq 0 ]; then
echo 'Congratulations! All Go source files have been linted.'
else
{
echo "Errors from golint:"
for err in "${errors[@]}"; do
echo "$err"
done
echo
echo 'Please fix the above errors. You can test via "golint" and commit the result.'
echo
} >&2
false
fi

View file

@ -1,32 +0,0 @@
#!/usr/bin/env bash
export SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "${SCRIPTDIR}/.validate"
IFS=$'\n'
files=( $(validate_diff --diff-filter=ACMR --name-only -- '*.go' | grep -v '^vendor/' | grep -v '^api/types/container/' || true) )
unset IFS
errors=()
for f in "${files[@]}"; do
failedVet=$(go vet "$f")
if [ "$failedVet" ]; then
errors+=( "$failedVet" )
fi
done
if [ ${#errors[@]} -eq 0 ]; then
echo 'Congratulations! All Go source files have been vetted.'
else
{
echo "Errors from go vet:"
for err in "${errors[@]}"; do
echo " - $err"
done
echo
echo 'Please fix the above errors. You can test via "go vet" and commit the result.'
echo
} >&2
false
fi

View file

@ -103,7 +103,7 @@ func (s *DockerSuite) TestStartPausedContainer(c *check.C) {
// an error should have been shown that you cannot start paused container
c.Assert(err, checker.NotNil, check.Commentf("out: %s", out))
// an error should have been shown that you cannot start paused container
c.Assert(out, checker.Contains, "Cannot start a paused container, try unpause instead.")
c.Assert(out, checker.Contains, "cannot start a paused container, try unpause instead")
}
func (s *DockerSuite) TestStartMultipleContainers(c *check.C) {

View file

@ -595,7 +595,7 @@ func createTarFile(path, extractDir string, hdr *tar.Header, reader io.Reader, L
return nil
default:
return fmt.Errorf("Unhandled tar header type %d\n", hdr.Typeflag)
return fmt.Errorf("unhandled tar header type %d", hdr.Typeflag)
}
// Lchown is not supported on Windows.

View file

@ -7,6 +7,7 @@ import (
"testing"
"time"
"github.com/stretchr/testify/assert"
"golang.org/x/net/context"
)
@ -14,7 +15,7 @@ import (
type errorReader struct{}
func (r *errorReader) Read(p []byte) (int, error) {
return 0, fmt.Errorf("Error reader always fail.")
return 0, fmt.Errorf("error reader always fail")
}
func TestReadCloserWrapperClose(t *testing.T) {
@ -35,9 +36,7 @@ func TestReaderErrWrapperReadOnError(t *testing.T) {
called = true
})
_, err := wrapper.Read([]byte{})
if err == nil || !strings.Contains(err.Error(), "Error reader always fail.") {
t.Fatalf("readErrWrapper should returned an error")
}
assert.EqualError(t, err, "error reader always fail")
if !called {
t.Fatalf("readErrWrapper should have call the anonymous function on failure")
}

View file

@ -8,11 +8,10 @@ import (
"strings"
"time"
"github.com/Nvveen/Gotty"
gotty "github.com/Nvveen/Gotty"
"github.com/docker/docker/pkg/jsonlog"
"github.com/docker/docker/pkg/term"
"github.com/docker/go-units"
units "github.com/docker/go-units"
)
// JSONError wraps a concrete Code and Message, `Code` is
@ -187,7 +186,7 @@ func cursorDown(out io.Writer, ti termInfo, l int) {
func (jm *JSONMessage) Display(out io.Writer, termInfo termInfo) error {
if jm.Error != nil {
if jm.Error.Code == 401 {
return fmt.Errorf("Authentication is required.")
return fmt.Errorf("authentication is required")
}
return jm.Error
}

View file

@ -10,6 +10,7 @@ import (
"github.com/docker/docker/pkg/jsonlog"
"github.com/docker/docker/pkg/term"
"github.com/stretchr/testify/assert"
)
func TestError(t *testing.T) {
@ -198,9 +199,7 @@ func TestJSONMessageDisplayWithJSONError(t *testing.T) {
jsonMessage = JSONMessage{Error: &JSONError{401, "Anything"}}
err = jsonMessage.Display(data, &noTermInfo{})
if err == nil || err.Error() != "Authentication is required." {
t.Fatalf("Expected an error \"Authentication is required.\", got %q", err)
}
assert.EqualError(t, err, "authentication is required")
}
func TestDisplayJSONMessagesStreamInvalidJSON(t *testing.T) {

View file

@ -61,7 +61,7 @@ func (r *Result) Assert(t testingT, exp Expected) *Result {
}
_, file, line, ok := runtime.Caller(1)
if ok {
t.Fatalf("at %s:%d - %s", filepath.Base(file), line, err.Error())
t.Fatalf("at %s:%d - %s\n", filepath.Base(file), line, err.Error())
} else {
t.Fatalf("(no file/line info) - %s", err.Error())
}
@ -108,7 +108,7 @@ func (r *Result) Compare(exp Expected) error {
if len(errors) == 0 {
return nil
}
return fmt.Errorf("%s\nFailures:\n%s\n", r, strings.Join(errors, "\n"))
return fmt.Errorf("%s\nFailures:\n%s", r, strings.Join(errors, "\n"))
}
func matchOutput(expected string, actual string) bool {

View file

@ -29,7 +29,7 @@ func loginV1(authConfig *types.AuthConfig, apiEndpoint APIEndpoint, userAgent st
logrus.Debugf("attempting v1 login to registry endpoint %s", serverAddress)
if serverAddress == "" {
return "", "", systemError{errors.New("Server Error: Server Address not set.")}
return "", "", systemError{errors.New("server Error: Server Address not set")}
}
req, err := http.NewRequest("GET", serverAddress+"users/", nil)

View file

@ -354,7 +354,7 @@ func ValidateIndexName(val string) (string, error) {
val = "docker.io"
}
if strings.HasPrefix(val, "-") || strings.HasSuffix(val, "-") {
return "", fmt.Errorf("Invalid index name (%s). Cannot begin or end with a hyphen.", val)
return "", fmt.Errorf("invalid index name (%s). Cannot begin or end with a hyphen", val)
}
return val, nil
}

View file

@ -81,7 +81,7 @@ func ReadCertsDirectory(tlsConfig *tls.Config, directory string) error {
keyName := certName[:len(certName)-5] + ".key"
logrus.Debugf("cert: %s", filepath.Join(directory, f.Name()))
if !hasFile(fs, keyName) {
return fmt.Errorf("Missing key %s for client certificate %s. Note that CA certificates should use the extension .crt.", keyName, certName)
return fmt.Errorf("missing key %s for client certificate %s. Note that CA certificates should use the extension .crt", keyName, certName)
}
cert, err := tls.LoadX509KeyPair(filepath.Join(directory, certName), filepath.Join(directory, keyName))
if err != nil {

View file

@ -434,7 +434,7 @@ func (r *Session) GetRepositoryData(name reference.Named) (*RepositoryData, erro
// "Get https://index.docker.io/v1/repositories/library/busybox/images: i/o timeout"
// was a top search on the docker user forum
if isTimeout(err) {
return nil, fmt.Errorf("Network timed out while trying to connect to %s. You may want to check your internet connection or if you are behind a proxy.", repositoryTarget)
return nil, fmt.Errorf("network timed out while trying to connect to %s. You may want to check your internet connection or if you are behind a proxy", repositoryTarget)
}
return nil, fmt.Errorf("Error while pulling image: %v", err)
}