Skip to content

Commit 7f75ecf

Browse files
authored
Added Travis CI
Added Travis CI, fixed format, and a test to work in any timezone.
1 parent 55b5917 commit 7f75ecf

18 files changed

+135
-9
lines changed

.travis.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
language: go
2+
3+
go:
4+
- "1.11.x"
5+
6+
env:
7+
- GO111MODULE=on
8+
9+
install:
10+
- make install-tools
11+
- make deps
12+
13+
script:
14+
- make validate

Makefile

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
.PHONY: help test fmt vet simplify errcheck staticcheck lint shellcheck fix-fmt build
2+
3+
help: ## Show this help
4+
@echo "Help"
5+
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-20s\033[93m %s\n", $$1, $$2}'
6+
7+
##
8+
### Code validation
9+
validate: ## Run all validation targets: test, fmt, vet, lint (but no acceptance testing)
10+
validate: fmt vet test lint shellcheck
11+
12+
test: ## Run tests for all go packages
13+
@scripts/test.sh
14+
15+
fmt: ## Run goimports on all packages, printing files that don't match code-format if any
16+
@scripts/fmt.sh
17+
18+
vet: ## Run vet on all packages (more info running `go doc cmd/vet`)
19+
@scripts/vet.sh
20+
21+
deps: ## Prefetch deps to ensure required versions are downloaded
22+
@scripts/deps.sh
23+
24+
simplify: ## Run gosimple on all packages
25+
@scripts/simplify.sh
26+
27+
errcheck: ## Run errcheck to find ignored errors
28+
@scripts/errcheck.sh
29+
30+
staticcheck: ## Run staticcheck on the codebase
31+
@scripts/staticcheck.sh
32+
33+
lint: ## Run lint on the codebase, printing any style errors
34+
@scripts/lint.sh
35+
36+
shellcheck: ## Lint shell scripts for potential errors
37+
@scripts/shellcheck.sh
38+
39+
fix-fmt: ## Run goimports on all packages, fix files that don't match code-style
40+
@scripts/fix-fmt.sh
41+
42+
install-tools: ## Install the required tooling
43+
go get -u -v \
44+
golang.org/x/tools/cmd/goimports \
45+
golang.org/x/lint/golint

baggage_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package log
22

33
import (
4-
"github.com/stretchr/testify/assert"
54
"testing"
5+
6+
"github.com/stretchr/testify/assert"
67
)
78

89
func TestNewID(t *testing.T) {

example/example.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package main
33
import (
44
"fmt"
55

6-
"github.com/cabify/go-logging"
6+
log "github.com/cabify/go-logging"
77
)
88

99
func main() {

factory.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package log
22

33
import (
44
"context"
5-
65
)
76

87
// Factory provides context aware loggers.

formatter_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ package log
33
import (
44
"testing"
55
"time"
6+
67
"github.com/stretchr/testify/assert"
78
)
89

910
func TestDefaultFormatterHasRightDateFormat(t *testing.T) {
10-
// Mon, 11 Jun 2018 12:35:18.123 UTC
11-
ts := time.Unix(1528713318, 123000000)
11+
ts := time.Date(2018, 6, 11, 12, 35, 18, 123000000, time.Local)
1212
rec := Record{
13-
Level:INFO,
14-
Time: ts,
13+
Level: INFO,
14+
Time: ts,
1515
Message: "Hello World!",
1616
}
1717
line := DefaultFormatter.Format(&rec)

logtest/baggage.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
Package logtest is intended to be used by tests for checking that baggage values have been correctly set
3-
*/
3+
*/
44
package logtest
55

66
import (

no_debug_logger.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ type NoDebugLogger struct {
99

1010
func (NoDebugLogger) Debug(args ...interface{}) {}
1111
func (NoDebugLogger) Debugf(format string, args ...interface{}) {}
12-
func (NoDebugLogger) Debugln(args ...interface{}) {}
12+
func (NoDebugLogger) Debugln(args ...interface{}) {}

scripts/deps.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
go mod verify

scripts/errcheck.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
echo "Checking for ignored Go errors"
6+
errcheck -ignoretests ./...

scripts/fix-fmt.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
echo "Fixing Go formatting"
6+
# shellcheck disable=SC2044
7+
for f in $(find . -name '*.go' ! -path "./vendor/*" ! -path "./.cache/*") ; do
8+
if [ -n "$(goimports -d "$f")" ]; then
9+
echo "Fixing $f";
10+
goimports -w "$f";
11+
fi;
12+
done

scripts/fmt.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
echo "Checking Go file formatting"
6+
7+
# shellcheck disable=SC2044
8+
GOIMP=$(for f in $(find . -name '*.go' ! -path "./.cache/*" ! -path "./vendor/*" ! -name "bindata.go") ; do goimports -l "$f" ; done) && echo "$GOIMP" && test -z "$GOIMP"

scripts/lint.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
echo "Checking for style errors"
6+
golint ./...

scripts/shellcheck.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
echo "Checking shell scripts for errors"
6+
find . -type f -name "*.sh" ! -path "./vendor/*" ! -path "./.cache/*" -print0 | xargs -0 shellcheck

scripts/simplify.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
echo "Checking for Go simplifications"
6+
gosimple ./...

scripts/staticcheck.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
echo "Running static checks"
6+
staticcheck ./...

scripts/test.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
echo "Running unit tests"
6+
go test -race ./...

scripts/vet.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
set -euo pipefail
4+
5+
echo "Checking for common Go mistakes"
6+
go vet -printfuncs=Debug,Debugf,Debugln,Info,Infof,Infoln,Notice,Noticef,Noticeln,Error,Errorf,Errorln,Warning,Warningf,Warningln,Critical,Criticalf,Criticalln ./...

0 commit comments

Comments
 (0)