Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding code coverage generation #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,7 @@
*.im?
target
work
bin/
bin/

coverage.txt
coverage.html
23 changes: 16 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
SHELL := /bin/bash
GO := GO15VENDOREXPERIMENT=1 go
GOPATH := $(shell go env GOPATH)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is going to be clobbered by the buildpack.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is fine if it's over written by the buildpack. It was added mainly to guarantee a value is set for GOPATH when running locally.

NAME := REPLACE_ME_APP_NAME
OS := $(shell uname)
MAIN_GO := main.go
ROOT_PACKAGE := $(GIT_PROVIDER)/$(ORG)/$(NAME)
GO_VERSION := $(shell $(GO) version | sed -e 's/^[^0-9.]*\([0-9.]*\).*/\1/')
PACKAGE_DIRS := $(shell $(GO) list ./... | grep -v /vendor/)
PKGS := $(shell go list ./... | grep -v /vendor | grep -v generated)
PKGS := $(subst :,_,$(PKGS))
BUILDFLAGS := ''
CGO_ENABLED = 0
MODULE_ENABLED = on
VENDOR_DIR=vendor

all: build
Expand All @@ -19,16 +20,22 @@ check: fmt build test
build:
CGO_ENABLED=$(CGO_ENABLED) $(GO) build -ldflags $(BUILDFLAGS) -o bin/$(NAME) $(MAIN_GO)

test:
CGO_ENABLED=$(CGO_ENABLED) $(GO) test $(PACKAGE_DIRS) -test.v
ACC := $(GOPATH)/bin/go-acc
$(ACC): #leave modules off for this tool download so go.mod not updated
GO111MODULE=off $(GO) get github.com/ory/go-acc

test: $(ACC)
GO111MODULE=$(MODULE_ENABLED) $(ACC) -o coverage.txt $(PKGS)
$(GO) tool cover -html=coverage.txt -o coverage.html

full: $(PKGS)

install:
GOBIN=${GOPATH}/bin $(GO) install -ldflags $(BUILDFLAGS) $(MAIN_GO)

fmt:
@FORMATTED=`$(GO) fmt $(PACKAGE_DIRS)`
@FORMATTED=`$(GO) fmt $(PKGS)`
printf "$(FORMATTED)"
@([[ ! -z "$(FORMATTED)" ]] && printf "Fixed unformatted files:\n$(FORMATTED)") || true

clean:
Expand All @@ -41,11 +48,13 @@ linux:

FGT := $(GOPATH)/bin/fgt
$(FGT):
go get github.com/GeertJohan/fgt
#leave modules off for this tool download so go.mod not updated
GO111MODULE=off go get github.com/GeertJohan/fgt

GOLINT := $(GOPATH)/bin/golint
$(GOLINT):
go get github.com/golang/lint/golint
#leave modules off for this tool download so go.mod not updated
GO111MODULE=off go get github.com/golang/lint/golint

$(PKGS): $(GOLINT) $(FGT)
@echo "LINTING"
Expand All @@ -56,7 +65,7 @@ $(PKGS): $(GOLINT) $(FGT)
@go test -v $@

.PHONY: lint
lint: vendor | $(PKGS) $(GOLINT) # ❷
lint: $(PKGS) $(GOLINT)
@cd $(BASE) && ret=0 && for pkg in $(PKGS); do \
test -z "$$($(GOLINT) $$pkg | tee /dev/stderr)" || ret=1 ; \
done ; exit $$ret
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module github.com/jenkins-x-quickstarts/golang-http
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func handler(w http.ResponseWriter, r *http.Request) {
log.Printf("title: %s\n", title)
}

fmt.Fprintf(w, "Hello from: "+title+"\n")
fmt.Fprintf(w, "Hello from: %s\n", title)
}

func main() {
Expand Down