Navigation Menu

Skip to content

Commit

Permalink
all: enable metalinter in CI and fix multiple lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
cezarsa committed Sep 4, 2017
1 parent 546f277 commit 990f8ba
Show file tree
Hide file tree
Showing 26 changed files with 111 additions and 101 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -19,7 +19,7 @@ before_install:
- '[[ $TRAVIS_OS_NAME == "linux" ]] && sudo sysctl -w net.ipv6.conf.lo.disable_ipv6=0 || true'
script:
- ./go.test.bash
- '[[ $TRAVIS_GO_VERSION == "1.8" ]] && ./check-fmt.sh || true'
- make metalint
services:
- redis
- mongodb
Expand Down
15 changes: 15 additions & 0 deletions Makefile
Expand Up @@ -8,6 +8,14 @@ PYTHON := $(shell which python)
GHR := $(shell which ghr)
GITHUB_TOKEN := $(shell git config --global --get github.token || echo $$GITHUB_TOKEN)

LINTER_ARGS_SLOW = \
-j 4 --enable-gc -s vendor -e '.*/vendor/.*' --vendor --enable=misspell --enable=gofmt --enable=goimports --enable=unused \
--disable=dupl --disable=gocyclo --disable=errcheck --disable=golint --disable=interfacer --disable=gas \
--disable=structcheck --deadline=60m --tests

LINTER_ARGS = \
$(LINTER_ARGS_SLOW) --disable=staticcheck --disable=unused --disable=gosimple

release:
@if [ ! $(version) ]; then \
echo "version parameter is required... use: make release version=<value>"; \
Expand Down Expand Up @@ -73,4 +81,11 @@ build:
check-docs: build
./misc/check-all-cmds-docs.sh

metalint:
go get -u github.com/alecthomas/gometalinter; \
gometalinter --install; \
go install ./...; \
go test -i ./...; \
gometalinter $(LINTER_ARGS) ./...; \

.PHONY: doc docs release manpage
33 changes: 0 additions & 33 deletions check-fmt.sh

This file was deleted.

4 changes: 2 additions & 2 deletions tsuru/admin/event.go
Expand Up @@ -99,7 +99,6 @@ type EventBlockAdd struct {
owner string
targetType string
targetValue string
reason string
}

func (c *EventBlockAdd) Info() *cmd.Info {
Expand Down Expand Up @@ -133,7 +132,8 @@ func (c *EventBlockAdd) Run(context *cmd.Context, client *cmd.Client) error {
}
target := event.Target{}
if c.targetType != "" {
targetType, err := event.GetTargetType(c.targetType)
var targetType event.TargetType
targetType, err = event.GetTargetType(c.targetType)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion tsuru/admin/node.go
Expand Up @@ -372,7 +372,7 @@ func (c *ListNodesCmd) nodeMetadataMatchesFilters(node provision.NodeSpec) bool
}
continue
}
metaVal, _ := node.Metadata[key]
metaVal := node.Metadata[key]
if metaVal != value {
return false
}
Expand Down
18 changes: 11 additions & 7 deletions tsuru/admin/platform.go
Expand Up @@ -109,6 +109,9 @@ func (p *PlatformAdd) Run(context *cmd.Context, client *cmd.Client) error {
writer.WriteField("name", context.Args[0])
writer.Close()
url, err := cmd.GetURL("/platforms")
if err != nil {
return err
}
request, err := http.NewRequest("POST", url, &body)
if err != nil {
return err
Expand Down Expand Up @@ -136,13 +139,11 @@ func (p *PlatformAdd) Flags() *gnuflag.FlagSet {
}

type PlatformUpdate struct {
name string
dockerfile string
image string
forceUpdate bool
disable bool
enable bool
fs *gnuflag.FlagSet
dockerfile string
image string
disable bool
enable bool
fs *gnuflag.FlagSet
}

func (p *PlatformUpdate) Info() *cmd.Info {
Expand Down Expand Up @@ -205,6 +206,9 @@ func (p *PlatformUpdate) Run(context *cmd.Context, client *cmd.Client) error {
writer.WriteField("disabled", disable)
writer.Close()
url, err := cmd.GetURL(fmt.Sprintf("/platforms/%s", name))
if err != nil {
return err
}
request, err := http.NewRequest("PUT", url, &body)
if err != nil {
return err
Expand Down
6 changes: 6 additions & 0 deletions tsuru/admin/platform_test.go
Expand Up @@ -300,6 +300,7 @@ func (s *S) TestPlatformUpdateRun(c *check.C) {
expectedMsg := "--something--\nPlatform successfully updated!\n"
msg := io.SimpleJsonMessage{Message: expectedMsg}
result, err := json.Marshal(msg)
c.Assert(err, check.IsNil)
trans := &cmdtest.ConditionalTransport{
Transport: cmdtest.Transport{Message: string(result), Status: http.StatusOK},
CondFunc: func(req *http.Request) bool {
Expand Down Expand Up @@ -332,6 +333,7 @@ func (s *S) TestPlatformUpdateRunLocalDockerfile(c *check.C) {
expectedMsg := "--something--\nPlatform successfully updated!\n"
msg := io.SimpleJsonMessage{Message: expectedMsg}
result, err := json.Marshal(msg)
c.Assert(err, check.IsNil)
trans := &cmdtest.ConditionalTransport{
Transport: cmdtest.Transport{Message: string(result), Status: http.StatusOK},
CondFunc: func(req *http.Request) bool {
Expand Down Expand Up @@ -364,6 +366,7 @@ func (s *S) TestPlatformUpdateRunPrebuiltImage(c *check.C) {
expectedMsg := "--something--\nPlatform successfully updated!\n"
msg := io.SimpleJsonMessage{Message: expectedMsg}
result, err := json.Marshal(msg)
c.Assert(err, check.IsNil)
trans := &cmdtest.ConditionalTransport{
Transport: cmdtest.Transport{Message: string(result), Status: http.StatusOK},
CondFunc: func(req *http.Request) bool {
Expand Down Expand Up @@ -396,6 +399,7 @@ func (s *S) TestPlatformUpdateRunImplicitImage(c *check.C) {
expectedMsg := "--something--\nPlatform successfully updated!\n"
msg := io.SimpleJsonMessage{Message: expectedMsg}
result, err := json.Marshal(msg)
c.Assert(err, check.IsNil)
trans := &cmdtest.ConditionalTransport{
Transport: cmdtest.Transport{Message: string(result), Status: http.StatusOK},
CondFunc: func(req *http.Request) bool {
Expand Down Expand Up @@ -427,6 +431,7 @@ func (s *S) TestPlatformUpdateWithFlagDisableTrue(c *check.C) {
expectedMsg := "Platform successfully updated!\n"
msg := io.SimpleJsonMessage{Message: expectedMsg}
result, err := json.Marshal(msg)
c.Assert(err, check.IsNil)
trans := &cmdtest.ConditionalTransport{
Transport: cmdtest.Transport{Message: string(result), Status: http.StatusOK},
CondFunc: func(req *http.Request) bool {
Expand Down Expand Up @@ -455,6 +460,7 @@ func (s *S) TestPlatformUpdateWithFlagEnabledTrue(c *check.C) {
expectedMsg := "Platform successfully updated!\n"
msg := io.SimpleJsonMessage{Message: expectedMsg}
result, err := json.Marshal(msg)
c.Assert(err, check.IsNil)
trans := &cmdtest.ConditionalTransport{
Transport: cmdtest.Transport{Message: string(result), Status: http.StatusOK},
CondFunc: func(req *http.Request) bool {
Expand Down
9 changes: 9 additions & 0 deletions tsuru/admin/pool.go
Expand Up @@ -67,6 +67,9 @@ func (c *AddPoolToSchedulerCmd) Run(ctx *cmd.Context, client *cmd.Client) error
v.Set("force", strconv.FormatBool(c.forceDefault))
v.Set("provisioner", c.provisioner)
u, err := cmd.GetURL("/pools")
if err != nil {
return err
}
err = doRequest(client, u, "POST", v.Encode())
if err != nil {
if e, ok := err.(*errors.HTTP); ok && e.Code == http.StatusPreconditionFailed {
Expand Down Expand Up @@ -126,6 +129,9 @@ func (c *UpdatePoolToSchedulerCmd) Run(ctx *cmd.Context, client *cmd.Client) err
}
v.Set("force", strconv.FormatBool(c.forceDefault))
u, err := cmd.GetURL(fmt.Sprintf("/pools/%s", ctx.Args[0]))
if err != nil {
return err
}
err = doRequest(client, u, "PUT", v.Encode())
if err != nil {
if e, ok := err.(*errors.HTTP); ok && e.Code == http.StatusPreconditionFailed {
Expand All @@ -134,6 +140,9 @@ func (c *UpdatePoolToSchedulerCmd) Run(ctx *cmd.Context, client *cmd.Client) err
successMessage := "Pool successfully updated.\n"
v.Set("force", "true")
u, err = cmd.GetURL(fmt.Sprintf("/pools/%s", ctx.Args[0]))
if err != nil {
return err
}
return confirmAction(ctx, client, u, "PUT", v.Encode(), retryMessage, failMessage, successMessage)
}
return err
Expand Down
5 changes: 4 additions & 1 deletion tsuru/admin/services.go
Expand Up @@ -180,6 +180,9 @@ func (c *ServiceDocAdd) Run(ctx *cmd.Context, client *cmd.Client) error {
}
docPath := ctx.Args[1]
b, err := ioutil.ReadFile(docPath)
if err != nil {
return err
}
v := url.Values{}
v.Set("doc", string(b))
request, err := http.NewRequest("PUT", u, strings.NewReader(v.Encode()))
Expand Down Expand Up @@ -266,10 +269,10 @@ endpoint:
production: production-endpoint.com`
template = fmt.Sprintf(template, pass)
f, err := os.Create("manifest.yaml")
defer f.Close()
if err != nil {
return errors.New("Error while creating manifest template.\nOriginal error message is: " + err.Error())
}
defer f.Close()
f.Write([]byte(template))
fmt.Fprintln(ctx.Stdout, `Generated file "manifest.yaml" in current directory`)
return nil
Expand Down
1 change: 1 addition & 0 deletions tsuru/admin/services_test.go
Expand Up @@ -263,6 +263,7 @@ func (s *S) TestServiceTemplateRun(c *check.C) {
f, err := os.Open("./manifest.yaml")
c.Assert(err, check.IsNil)
fc, err := ioutil.ReadAll(f)
c.Assert(err, check.IsNil)
manifest := `id: servicename
username: username_to_auth
password: .{16}
Expand Down
1 change: 1 addition & 0 deletions tsuru/admin/testdata/doc.md
@@ -0,0 +1 @@
my doc
2 changes: 1 addition & 1 deletion tsuru/client/apps.go
Expand Up @@ -831,7 +831,7 @@ func (c *AppList) Show(result []byte, context *cmd.Context, client *cmd.Client)
}
table.Headers = cmd.Row([]string{"Application", "Units", "Address"})
for _, app := range apps {
summary := ""
var summary string
if app.Error == "" {
unitsStatus := make(map[string]int)
for _, unit := range app.Units {
Expand Down
2 changes: 1 addition & 1 deletion tsuru/client/certificate.go
Expand Up @@ -79,7 +79,7 @@ func (c *CertificateSet) Run(context *cmd.Context, client *cmd.Client) error {
return err
}
defer response.Body.Close()
fmt.Fprintln(context.Stdout, "Succesfully created the certificated.")
fmt.Fprintln(context.Stdout, "Successfully created the certificated.")
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion tsuru/client/certificate_test.go
Expand Up @@ -47,7 +47,7 @@ func (s *S) TestCertificateSetRunSuccessfully(c *check.C) {
c.Assert(command.cname, check.Equals, "app.io")
err := command.Run(&context, client)
c.Assert(err, check.IsNil)
c.Assert(stdout.String(), check.Equals, "Succesfully created the certificated.\n")
c.Assert(stdout.String(), check.Equals, "Successfully created the certificated.\n")
}

func (s *S) TestCertificateSetRunCerticateNotFound(c *check.C) {
Expand Down
3 changes: 1 addition & 2 deletions tsuru/client/deploy.go
Expand Up @@ -710,7 +710,6 @@ func (c *AppDeployRollbackUpdate) Run(context *cmd.Context, client *cmd.Client)
return err
}
request.Header.Add("Content-Type", "application/x-www-form-urlencoded")
response, err := client.Do(request)
defer response.Body.Close()
_, err = client.Do(request)
return err
}
9 changes: 4 additions & 5 deletions tsuru/client/deploy_test.go
Expand Up @@ -553,7 +553,6 @@ func (s *S) TestAppDeployRollbackUpdateDisabling(c *check.C) {
func (s *S) TestProcessTsuruIgnore(c *check.C) {
dir, _ := os.Getwd()
tests := []struct {
name string
pattern string
path []string
want map[string]struct{}
Expand All @@ -562,16 +561,16 @@ func (s *S) TestProcessTsuruIgnore(c *check.C) {
pattern: "*.txt",
path: []string{filepath.Join(dir, "testdata", "deploy")},
want: map[string]struct{}{
filepath.Join(dir, "testdata/deploy/file2.txt"): struct{}{},
filepath.Join(dir, "testdata/deploy/directory/file.txt"): struct{}{},
filepath.Join(dir, "testdata/deploy/file1.txt"): struct{}{},
filepath.Join(dir, "testdata/deploy/file2.txt"): {},
filepath.Join(dir, "testdata/deploy/directory/file.txt"): {},
filepath.Join(dir, "testdata/deploy/file1.txt"): {},
},
},
{
pattern: "file2.txt",
path: []string{filepath.Join(dir, "testdata/deploy/file2.txt"), filepath.Join(dir, "testdata/deploy/file1.txt")},
want: map[string]struct{}{
filepath.Join(dir, "testdata/deploy/file2.txt"): struct{}{},
filepath.Join(dir, "testdata/deploy/file2.txt"): {},
},
},
}
Expand Down
9 changes: 4 additions & 5 deletions tsuru/client/services.go
Expand Up @@ -109,6 +109,9 @@ func (c *ServiceInstanceAdd) Run(ctx *cmd.Context, client *cmd.Client) error {
return err
}
request, err := http.NewRequest("POST", u, strings.NewReader(v.Encode()))
if err != nil {
return err
}
request.Header.Set("Content-Type", "application/x-www-form-urlencoded")
_, err = client.Do(request)
if err != nil {
Expand Down Expand Up @@ -667,11 +670,7 @@ func (c *ServiceInstanceRemove) Run(ctx *cmd.Context, client *cmd.Client) error
if err != nil {
return err
}
err = cmd.StreamJSONResponse(ctx.Stdout, resp)
if err != nil {
return err
}
return nil
return cmd.StreamJSONResponse(ctx.Stdout, resp)
}

func (c *ServiceInstanceRemove) Flags() *gnuflag.FlagSet {
Expand Down
4 changes: 2 additions & 2 deletions tsuru/client/tag.go
Expand Up @@ -73,7 +73,7 @@ func loadApps(client *cmd.Client) ([]app, error) {
}
var apps []app
err = json.Unmarshal(result, &apps)
return apps, nil
return apps, err
}

func loadServices(client *cmd.Client) ([]service.ServiceModel, error) {
Expand All @@ -83,7 +83,7 @@ func loadServices(client *cmd.Client) ([]service.ServiceModel, error) {
}
var services []service.ServiceModel
err = json.Unmarshal(result, &services)
return services, nil
return services, err
}

func getFromURL(path string, client *cmd.Client) ([]byte, error) {
Expand Down
3 changes: 3 additions & 0 deletions tsuru/client/volume.go
Expand Up @@ -310,6 +310,9 @@ func (c *VolumeDelete) Run(ctx *cmd.Context, client *cmd.Client) error {
return err
}
request, err := http.NewRequest("DELETE", u, nil)
if err != nil {
return err
}
_, err = client.Do(request)
if err != nil {
return err
Expand Down
14 changes: 0 additions & 14 deletions tsuru/installer/components.go
Expand Up @@ -11,7 +11,6 @@ import (
"strings"

"github.com/docker/machine/libmachine/mcnutils"
"github.com/fsouza/go-dockerclient"
"github.com/tsuru/tsuru-client/tsuru/admin"
tclient "github.com/tsuru/tsuru-client/tsuru/client"
"github.com/tsuru/tsuru/cmd"
Expand Down Expand Up @@ -53,19 +52,6 @@ type iaasConfigDriver struct {
Options map[string]interface{} `yaml:"options,omitempty"`
}

func (c *TsuruAPI) setupRootUser(cluster ServiceCluster, email, password string) error {
cmd := []string{"tsurud", "root-user-create", email}
passwordConfirmation := strings.NewReader(fmt.Sprintf("%s\n%s\n", password, password))
startOpts := docker.StartExecOptions{
InputStream: passwordConfirmation,
Detach: false,
OutputStream: os.Stdout,
ErrorStream: os.Stderr,
RawTerminal: true,
}
return cluster.ServiceExec("tsuru_tsuru", cmd, startOpts)
}

type Bootstraper interface {
Bootstrap(opts BoostrapOptions) error
}
Expand Down

0 comments on commit 990f8ba

Please sign in to comment.