Skip to content

Commit

Permalink
testing procedure cleanup and docs (bold-commerce#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
luthermonson authored Apr 10, 2020
1 parent 6272228 commit c833331
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 16 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ go:
- "1.12"
- "1.13"
- "1.14"
install:
- make travis
script:
- go test -coverprofile=coverage.txt
after_success:
- bash <(curl -s https://codecov.io/bash)

8 changes: 2 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
FROM golang:1.9
FROM golang:1.14-alpine

# This is similar to the golang-onbuild image but with different paths and
# test-dependencies loaded as well.
ENV CGO_ENABLED=0
RUN mkdir -p /go/src/github.com/bold-commerce/go-shopify
WORKDIR /go/src/github.com/bold-commerce/go-shopify

COPY . /go/src/github.com/bold-commerce/go-shopify
RUN go get -v -d -t
14 changes: 14 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
container:
@docker-compose build test
travis:
@go get -v -d -t
test:
@docker-compose run --rm test
coverage:
@docker-compose run --rm test sh -c 'go test -coverprofile=coverage.out ./... && go tool cover -html coverage.out -o coverage.html'
@open coverage.html
clean:
@docker image rm go-shopify
@rm -f coverage.html coverage.out

.DEFAULT_GOAL := container
63 changes: 56 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,29 @@ client := goshopify.NewClient(app, "shopname", "")
// Fetch the number of products.
numProducts, err := client.Product.Count(nil)
```
### Client Options
When creating a client there are configuration options you can pass to NewClient. Simply use the last variadic param and
pass in the built in options or create your own and manipulate the client. See [options.go](https://github.com/bold-commerce/go-shopify/blob/master/options.go)
for more details.

#### WithVersion
Read more details on the [Shopify API Versioning](https://shopify.dev/concepts/about-apis/versioning)
to understand the format and release schedules. You can use `WithVersion` to specify a specific version
of the API. If you do not use this option you will be defaulted to the oldest stable API.

```go
client := goshopify.NewClient(app, "shopname", "", goshopify.WithVersion("2019-04"))
```

#### WithRetry
Shopify [Rate Limits](https://shopify.dev/concepts/about-apis/rate-limits) their API and if this happens to you they
will send a back off (usually 2s) to tell you to retry your request. To support this functionality seamlessly within
the client a `WithRetry` option exists where you can pass an `int` of how many times you wish to retry per-request
before returning an error. `WithRetry` additionally supports retrying HTTP503 errors.

```go
client := goshopify.NewClient(app, "shopname", "", goshopify.WithRetry(3))
```

#### Query options

Expand Down Expand Up @@ -176,14 +199,40 @@ func ValidateWebhook(httpRequest *http.Request) (bool) {
```

## Develop and test
`docker` and `docker-compose` must be installed

### Mac/Linux/Windows with make
Using the make file is the easiest way to get started with the tests and wraps the manual steps below with easy to use
make commands.

There's nothing special to note about the tests except that if you have Docker
and Compose installed, you can test like this:
```shell
make && make test
```
#### Makefile goals
* `make` or `make container`: default goal is to make the `go-shopify:latest` build container
* `make test`: run go test in the container
* `make clean`: deletes the `go-shopify:latest` image and coverage output
* `make coverage`: generates the coverage.html and opens it

### Manually
To run the tests you will need the `go-shopify:latest` image built to run your tests, to do this run
```
docker-compose build test
```

$ docker-compose build dev
$ docker-compose run --rm dev
To run tests you can use run
```shell
docker-compose run --rm tests
```

Testing the package is the default command for the dev container. To create a
coverage profile:
To create a coverage profile run the following to generate a coverage.html
```
docker-compose run --rm dev sh -c 'go test -coverprofile=coverage.out ./... && go tool cover -html coverage.out -o coverage.html'
```

When done testing and you want to cleanup simply run
```
docker image rm go-shopify:latest
```

$ docker-compose run --rm dev bash -c 'go test -coverprofile=coverage.out ./... && go tool cover -html coverage.out -o coverage.html'
Read the docker-compose.yml and Dockerfile for further details.
5 changes: 3 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
version: '2'
version: '3.7'

services:
dev:
test:
image: go-shopify:latest
build: .
command: go test -v -cover ./...
volumes:
Expand Down
25 changes: 25 additions & 0 deletions make.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
@echo off
if "%1%"=="" (
set cmd=container
) else (
set cmd=%1%
)
if "%cmd%"=="container" (
docker-compose build test
goto :eof
)
if "%cmd%"=="test" (
docker-compose run --rm test
goto :eof
)
if "%cmd%"=="coverage" (
docker-compose run --rm test sh -c "go test -coverprofile=coverage.out ./... && go tool cover -html coverage.out -o coverage.html"
coverage.html
goto :eof
)
if "%cmd%"=="clean" (
docker image rm go-shopify
del coverage.html
del coverage.out
goto :eof
)

0 comments on commit c833331

Please sign in to comment.