Skip to content
This repository has been archived by the owner on Oct 27, 2022. It is now read-only.

Commit

Permalink
Improve test targets to use packr2 idiomatically
Browse files Browse the repository at this point in the history
- not quite idiomatic because 'packr2 build' should preclude needing 'go build'
  - could not make that work
- added 'packr2 build' as file targets
- added documentation to help when working with packr
- made builds a little more efficient, see cf-platform-eng/marman#3

Co-authored-by: Pete Wall <[email protected]>
[#165363463]
  • Loading branch information
Rasheed Abdul-Aziz committed Jul 10, 2019
1 parent 0fc32bd commit 42de6ad
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 15 deletions.
34 changes: 19 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ GO-VER = go1.12
default: build

# #### GO Binary Management ####

deps-go-binary:
echo "Expect: $(GO-VER)" && \
echo "Actual: $$(go version)" && \
Expand All @@ -16,7 +17,9 @@ ifndef HAS_GO_IMPORTS
go get -u golang.org/x/tools/cmd/goimports
endif


# #### CLEAN ####

clean-packr: deps-packr
packr2 clean

Expand All @@ -25,6 +28,7 @@ clean: deps-go-binary clean-packr
go clean --modcache

# #### DEPS ####

deps-modules: deps-goimports deps-go-binary
go mod download

Expand All @@ -34,43 +38,43 @@ deps-packr: deps-modules
deps-counterfeiter: deps-modules
command -v counterfeiter >/dev/null 2>&1 || go get -u github.com/maxbrunsfeld/counterfeiter/v6


deps: deps-modules deps-packr deps-counterfeiter


# #### BUILD ####
SRC = $(shell find . -name "*.go" | grep -v "_test\." )

GENERATE_ARTIFACTS = generate/generate-packr.go packrd/packed-packr.go
SRC = $(shell find . -name "*.go" | grep -v "_test\." )
VERSION := $(or $(VERSION), "dev")

LDFLAGS="-X github.com/cf-platform-eng/mrreport/version.Version=$(VERSION)"

build/mrreport: $(SRC) deps
$(GENERATE_ARTIFACTS): html/index.html
packr2 build
go build -o build/mrreport -ldflags ${LDFLAGS} ./cmd/mrreport/main.go

build: build/mrreport
build/mrreport: $(SRC) $(GENERATE_ARTIFACTS)
go build -o build/mrreport -ldflags ${LDFLAGS} ./cmd/mrreport/main.go

build: deps build/mrreport

build/mrreport-linux:
packr2 build
build/mrreport-linux: $(SRC) $(GENERATE_ARTIFACTS)
GOARCH=amd64 GOOS=linux go build -o build/mrreport-linux -ldflags ${LDFLAGS} ./cmd/mrreport/main.go

build-linux: build/mrreport-linux
build-linux: deps build/mrreport-linux

build/mrreport-darwin:
packr2 build
build/mrreport-darwin: $(SRC) $(GENERATE_ARTIFACTS)
GOARCH=amd64 GOOS=darwin go build -o build/mrreport-darwin -ldflags ${LDFLAGS} ./cmd/mrreport/main.go

build-darwin: build/mrreport-darwin
build-darwin: deps build/mrreport-darwin

build-all: build-linux build-darwin


# #### TESTS ####
units: deps
ginkgo -r -skipPackage features .

features: deps
units: deps # units test without packr content
ginkgo -r -tags=skippackr -skipPackage features .

features: deps $(GENERATE_ARTIFACTS)
ginkgo -r -tags=feature features

test: deps lint units features
Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,15 @@ mrreport takes log data from stdin, generates an HTML report, and outputs in on
```bash
cat logfile.log | mrreport generate > report.html
```

## Testing

When you're testing, `packr` will use the generated content if it exists, not the content of `html/index.html`.

* `make units` will avoid using packr
* `make features` will regenerate using `packr2` and use the generated files

When working with other test-runners (e.g. goland's), make sure you either
* run them with the `skippackr`
* add a before-run step that does `packr2 build`

0 comments on commit 42de6ad

Please sign in to comment.