Skip to content

Commit

Permalink
fix lint errors and lint in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
cezarsa committed Jul 17, 2020
1 parent 50f0223 commit 21dc87f
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 20 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/go.yaml
@@ -0,0 +1,29 @@
name: ci
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v2
with:
go-version: 1.14
- uses: actions/checkout@v2
- uses: actions/cache@v2
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- run: go test -race

lint:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-go@v2
with:
go-version: 1.14
- uses: actions/checkout@v2
- run: curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin
- run: golangci-lint run -c ./.golangci.yml .

20 changes: 20 additions & 0 deletions .golangci.yml
@@ -0,0 +1,20 @@
run:
deadline: 30m
tests: true

linters-settings:
govet:
check-shadowing: true
gofmt:
simplify: true
maligned:
suggest-new: true

linters:
enable:
- goimports
- gofmt
- misspell
- maligned
disable:
- errcheck
12 changes: 0 additions & 12 deletions .travis.yml

This file was deleted.

4 changes: 2 additions & 2 deletions README.markdown
@@ -1,8 +1,8 @@
#Config

[![Build Status](https://secure.travis-ci.org/tsuru/config.png)](http://travis-ci.org/tsuru/config)
![ci](https://github.com/tsuru/config/workflows/ci/badge.svg)

[![GoDoc](http://godoc.org/github.com/tsuru/config?status.png)](http://godoc.org/github.com/tsuru/config)
[![PkgGoDev](https://pkg.go.dev/badge/github.com/tsuru/config)](https://pkg.go.dev/github.com/tsuru/config)

Config is a Go package to manage yaml configuration files.

Expand Down
5 changes: 2 additions & 3 deletions config.go
Expand Up @@ -431,9 +431,8 @@ func (c *Configuration) GetList(key string) ([]string, error) {
if err != nil {
return nil, err
}
switch value.(type) {
switch v := value.(type) {
case []interface{}:
v := value.([]interface{})
result := make([]string, len(v))
for i, item := range v {
switch v := item.(type) {
Expand All @@ -451,7 +450,7 @@ func (c *Configuration) GetList(key string) ([]string, error) {
}
return result, nil
case []string:
return value.([]string), nil
return v, nil
}
return nil, &InvalidValue{key, "list"}
}
Expand Down
9 changes: 6 additions & 3 deletions config_test.go
Expand Up @@ -21,7 +21,7 @@ type S struct{}

var _ = check.Suite(&S{})

var empty = make(map[interface{}]interface{}, 0)
var empty = make(map[interface{}]interface{})

var expected = map[interface{}]interface{}{
"database": map[interface{}]interface{}{
Expand Down Expand Up @@ -93,7 +93,7 @@ func (s *S) TestConfigFileIsAllInOrNothing(c *check.C) {
}

func (s *S) TestConfigFileUnknownFile(c *check.C) {
err := ReadConfigFile("/some/unknwon/file/path")
err := ReadConfigFile("/some/unknown/file/path")
c.Assert(err, check.NotNil)
}

Expand All @@ -114,7 +114,7 @@ func (s *S) TestWatchConfigFile(c *check.C) {
}

func (s *S) TestWatchConfigFileUnknownFile(c *check.C) {
err := ReadAndWatchConfigFile("/some/unknwon/file/path")
err := ReadAndWatchConfigFile("/some/unknown/file/path")
c.Assert(err, check.NotNil)
}

Expand Down Expand Up @@ -215,11 +215,13 @@ func (s *S) TestGetConfigReturnErrorsIfTheKeyIsNotFound(c *check.C) {
err = ReadConfigFile(configFile)
c.Assert(err, check.IsNil)
err = os.Setenv("DATABASE", "{\"host\":\"6.6.6.6\"}")
c.Assert(err, check.IsNil)
defer os.Unsetenv("DATABASE")
_, err = Get("database:port")
c.Assert(err, check.FitsTypeOf, ErrKeyNotFound{})
c.Assert(err.Error(), check.Equals, `key "database:port" not found`)
err = os.Setenv("DATABASE", "{\"mongo\": {\"host\":\"6.6.6.6\"}}")
c.Assert(err, check.IsNil)
_, err = Get("database:mongo:port")
c.Assert(err, check.FitsTypeOf, ErrKeyNotFound{})
c.Assert(err.Error(), check.Equals, `key "database:mongo:port" not found`)
Expand Down Expand Up @@ -359,6 +361,7 @@ func (s *S) TestGetInt(c *check.C) {
c.Assert(value, check.Equals, 8080)
value, err = GetInt("xpto")
c.Assert(err, check.NotNil)
c.Assert(value, check.Equals, 0)
value, err = GetInt("something-unknown")
c.Assert(err, check.NotNil)
c.Assert(value, check.Equals, 0)
Expand Down
10 changes: 10 additions & 0 deletions go.mod
@@ -0,0 +1,10 @@
module github.com/tsuru/config

go 1.14

require (
github.com/howeyc/fsnotify v0.9.0
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f
gopkg.in/yaml.v2 v2.3.0
)
12 changes: 12 additions & 0 deletions go.sum
@@ -0,0 +1,12 @@
github.com/howeyc/fsnotify v0.9.0 h1:0gtV5JmOKH4A8SsFxG2BczSeXWWPvcMT0euZt5gDAxY=
github.com/howeyc/fsnotify v0.9.0/go.mod h1:41HzSPxBGeFRQKEEwgh49TRw/nKBsYZ2cF1OzPjSJsA=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=

0 comments on commit 21dc87f

Please sign in to comment.