Skip to content

Commit

Permalink
Add travis build and coverage (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
yurishkuro authored Nov 8, 2016
1 parent e922ce6 commit f315191
Show file tree
Hide file tree
Showing 10 changed files with 200 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@
*.test
*.xml
*.swp
fmt.log
lint.log
cover.html
.idea/
.tmp/
_site/
env/
Gemfile.lock
vendor/
17 changes: 17 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
sudo: required

language: go

go:
- 1.7

services:
- docker

install:
- make install_ci

script:
- make test_ci
- travis_retry goveralls -coverprofile=cover.out -service=travis-ci || true

68 changes: 68 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
PROJECT_ROOT=github.com/uber/jaeger
PACKAGES := $(shell glide novendor | grep -v ./thrift-gen/...)

# all .go files that don't exist in hidden directories
ALL_SRC := $(shell find . -name "*.go" | grep -v -e vendor -e thrift-gen \
-e ".*/\..*" \
-e ".*/_.*" \
-e ".*/mocks.*")

export GO15VENDOREXPERIMENT=1

RACE=-race
GOTEST=go test -v $(RACE)
GOLINT=golint
GOVET=go vet
GOFMT=gofmt
FMT_LOG=fmt.log
LINT_LOG=lint.log

PASS=$(shell printf "\033[32mPASS\033[0m")
FAIL=$(shell printf "\033[31mFAIL\033[0m")
COLORIZE=sed ''/PASS/s//$(PASS)/'' | sed ''/FAIL/s//$(FAIL)/''

.DEFAULT_GOAL := test-and-lint

.PHONY: test-and-lint
test-and-lint: test fmt lint

.PHONY: test
test:
$(GOTEST) $(PACKAGES) | $(COLORIZE)

.PHONY: fmt
fmt:
$(GOFMT) -e -s -l -w $(ALL_SRC)

.PHONY: lint
lint:
$(GOVET) $(PACKAGES)
@cat /dev/null > $(LINT_LOG)
@$(foreach pkg, $(PACKAGES), $(GOLINT) $(pkg) | grep -v crossdock/thrift >> $(LINT_LOG) || true;)
@[ ! -s "$(LINT_LOG)" ] || (echo "Lint Failures" | cat - $(LINT_LOG) && false)
@$(GOFMT) -e -s -l $(ALL_SRC) > $(FMT_LOG)
@[ ! -s "$(FMT_LOG)" ] || (echo "Go Fmt Failures, run 'make fmt'" | cat - $(FMT_LOG) && false)

.PHONY: install
install:
glide --version || go get github.com/Masterminds/glide
glide install

.PHONY: cover
cover:
./scripts/cover.sh $(shell go list $(PACKAGES))
go tool cover -html=cover.out -o cover.html

.PHONY: install_ci
install_ci: install
go get github.com/wadey/gocovmerge
go get github.com/mattn/goveralls
go get golang.org/x/tools/cmd/cover
go get github.com/golang/lint/golint


.PHONY: test_ci
test_ci:
@./scripts/cover.sh $(shell go list $(PACKAGES))
make lint

Empty file added cmd/agent/.nocover
Empty file.
5 changes: 5 additions & 0 deletions cmd/agent/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package main

func main() {
println("jaeger-agent")
}
10 changes: 10 additions & 0 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions glide.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
package: github.com/uber/jaeger
import:
- package: github.com/uber/jaeger-lib
- package: github.com/uber-go/zap
60 changes: 60 additions & 0 deletions scripts/cover.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/bin/bash

set -e

COVER=.cover
ROOT_PKG=github.com/uber/jaeger/

if [[ -d "$COVER" ]]; then
rm -rf "$COVER"
fi
mkdir -p "$COVER"

# If a package directory has a .nocover file, don't count it when calculating
# coverage.
filter=""
for pkg in "$@"; do
if [[ -f "$GOPATH/src/$pkg/.nocover" ]]; then
if [[ -n "$filter" ]]; then
filter="$filter, "
fi
filter="\"$pkg\": true"
fi
done

i=0
for pkg in "$@"; do
i=$((i + 1))

extracoverpkg=""
if [[ -f "$GOPATH/src/$pkg/.extra-coverpkg" ]]; then
extracoverpkg=$( \
sed -e "s|^|$pkg/|g" < "$GOPATH/src/$pkg/.extra-coverpkg" \
| tr '\n' ',')
fi

coverpkg=$(go list -json "$pkg" | jq -r '
.Deps
| . + ["'"$pkg"'"]
| map
( select(startswith("'"$ROOT_PKG"'"))
| select(contains("/vendor/") | not)
| select(in({'"$filter"'}) | not)
)
| join(",")
')
if [[ -n "$extracoverpkg" ]]; then
coverpkg="$extracoverpkg$coverpkg"
fi

if [[ -z "$coverpkg" ]]; then
continue
fi

args="-coverprofile $COVER/cover.${i}.out" # -coverpkg $coverpkg

echo go test -race "$pkg"
go test $args -race "$pkg"
done

gocovmerge "$COVER"/*.out > cover.out
24 changes: 24 additions & 0 deletions services/agent/agent.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package agent

import (
"github.com/uber-go/zap"
)

// Agent is a composition of all services / components
type Agent interface {
// Run starts all services of the Agent
// Run()
}

type agent struct {
logger zap.Logger
}

// New creates a new Jaeger Agent
func New(
logger zap.Logger,
) Agent {
return &agent{
logger: logger,
}
}
11 changes: 11 additions & 0 deletions services/agent/agent_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package agent_test

import (
"testing"

"github.com/uber/jaeger/services/agent"
)

func TestNewAgent(t *testing.T) {
agent.New(nil)
}

0 comments on commit f315191

Please sign in to comment.