Skip to content

Commit

Permalink
Merge pull request #15 from DavyJ0nes/general-maintainence
Browse files Browse the repository at this point in the history
General maintainence
  • Loading branch information
DavyJ0nes authored Aug 19, 2020
2 parents 2d6511e + eb864e9 commit e1cfc65
Show file tree
Hide file tree
Showing 16 changed files with 577 additions and 58 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/integration-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Integration Test
on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
# Run tests.
# See also https://docs.docker.com/docker-hub/builds/automated-testing/
test:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Run Integration Tests
run: make integrationtest
36 changes: 36 additions & 0 deletions .github/workflows/lint-and-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Lint and Test
on: [pull_request]

jobs:
lint:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Vendor Dependencies
run: go mod vendor

- name: Run Linter
run: make lint

test:
needs: lint
strategy:
matrix:
go-version: [1.13.x, 1.14.x]
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}

steps:
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go-version }}

- name: Checkout code
uses: actions/checkout@v2

- name: Test
run: make unittest
89 changes: 89 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
run:
concurrency: 4
timeout: 1m
issues-exit-code: 1
tests: true
skip-dirs-use-default: true
modules-download-mode: vendor
allow-parallel-runners: false


output:
# colored-line-number|line-number|json|tab|checkstyle|code-climate, default is "colored-line-number"
format: colored-line-number


linters-settings:
gocognit:
# minimal code complexity to report, 30 by default (but we recommend 10-20)
min-complexity: 10
nestif:
# minimal complexity of if statements to report, 5 by default
min-complexity: 4
goconst:
# minimal length of string constant, 3 by default
min-len: 3
# minimal occurrences count to trigger, 3 by default
min-occurrences: 3
gocritic:
# Which checks should be enabled; can't be combined with 'disabled-checks';
# See https://go-critic.github.io/overview#checks-overview
# To check which checks are enabled run `GL_DEBUG=gocritic golangci-lint run`
# By default list of stable checks is used.

# Enable multiple checks by tags, run `GL_DEBUG=gocritic golangci-lint run` to see all tags and checks.
# Empty list by default. See https://github.com/go-critic/go-critic#usage -> section "Tags".
enabled-tags:
- performance
disabled-tags:
- experimental

settings: # settings passed to gocritic
captLocal: # must be valid enabled check name
paramsOnly: true
rangeValCopy:
sizeThreshold: 32
gocyclo:
# minimal code complexity to report, 30 by default (but we recommend 10-20)
min-complexity: 10
godot:
# check all top-level comments, not only declarations
check-all: false


linters:
enable:
- megacheck
- govet
disable:
- maligned
- prealloc
- scopelint
- noctx
disable-all: false
presets:
- bugs
- unused
fast: false


severity:
# Default value is empty string.
# Set the default severity for issues. If severity rules are defined and the issues
# do not match or no severity is provided to the rule this will be the default
# severity applied. Severities should match the supported severity names of the
# selected out format.
# - Code climate: https://docs.codeclimate.com/docs/issues#issue-severity
# - Checkstyle: https://checkstyle.sourceforge.io/property_types.html#severity
# - Github: https://help.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-error-message
default-severity: error

# Default value is empty list.
# When a list of severity rules are provided, severity information will be added to lint
# issues. Severity rules have the same filtering capability as exclude rules except you
# are allowed to specify one matcher per severity rule.
# Only affects out formats that support setting severity information.
rules:
- linters:
- dupl
severity: info
20 changes: 0 additions & 20 deletions .travis.yml

This file was deleted.

47 changes: 47 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Contributing

<!-- vim-markdown-toc GFM -->

- [Pull Requests](#pull-requests)
- [Testing](#testing)
- [Unit Tests](#unit-tests)
- [Integration Tests](#integration-tests)

<!-- vim-markdown-toc -->

Thank you so much for wanting to contribute to the [stubby]() project.

I built the tool to help fulfil a need that I had with simplifying
testing and I hope that it helps you as well.

Below I have put some requests and tips for how to request and add features
and updates to the tool.

## Pull Requests

If you want to contribute an update or a change, could you fork the repository
and then open a pull request merging your fork into the upstream. This helps
to keep the history of this upstream tidy :).

## Testing

### Unit Tests

As stubby just returns configured HTTP responses, most of the testing is handled
within the [router](./router) package.

Please follow the conventions used within the [router_test.go](./router/router_test.go)
file and ensure that any new functionality is covered by a test, existing or
newly created.

### Integration Tests

A Docker Image is built for stubby to make using it within other repositories easier.

To help ensure the image that is provided works as expected, some integration tests
are run whenever a pull request is opened. These utilise [docker-compose](https://docs.docker.com/compose)
to build the stubby Docker Image and then run tests that interact with a running
version of stubby.

The integration tests are located in the [testing/](./testing) package. The associated Compose
file can be found [here](docker-compose.test.yml).
10 changes: 5 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ ARG APP_NAME=stubby
ARG MAIN_PATH=cmd/main.go

# -- Builder Image
FROM golang:1.13-stretch As Builder
FROM golang:1.14-stretch As Builder

ARG ORG_NAME
ARG REPO_NAME
Expand All @@ -21,9 +21,9 @@ ENV GO111MODULE=on
WORKDIR /go/src/github.com/${ORG_NAME}/${REPO_NAME}

# Set up dependencies
COPY ./go.mod go.mod
COPY ./go.sum go.sum
RUN go mod download
COPY ./go.mod go.mod
COPY ./go.sum go.sum
RUN go mod download

# Copy rest of the package code
COPY . .
Expand All @@ -32,7 +32,7 @@ COPY . .
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -tags netgo --installsuffix netgo -o $APP_NAME $MAIN_PATH

# -- Main Image
FROM alpine:3.10
FROM alpine:3.12

ARG ORG_NAME
ARG REPO_NAME
Expand Down
23 changes: 17 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,26 @@ run_image:
$(call blue, "# Running Docker Image Locally...")
@docker run -it --rm --name ${APP_NAME} -v ${PWD}/config.yaml:/config.yaml -p ${LOCAL_PORT}:${APP_PORT} ${USERNAME}/${APP_NAME}

## test: run test suites
.PHONY: test
test:
@go test -race ./... || (echo "go test failed $$?"; exit 1)

## lint: run golint on project
.PHONY: lint
lint:
@golint -set_exit_status $(shell find . -type d | grep -v "vendor" | grep -v ".git" | grep -v ".idea")
@docker run --rm -v ${PWD}:/app -w /app golangci/golangci-lint:v1.30.0 golangci-lint run

## test: alias for test
.PHONY: test
test: unittest

## unittest: run unit test suites
.PHONY: unittest
unittest:
@go test -v -race ./...

## integrationtest: run integration test suites
.PHONY: integrationtest
integrationtest:
@docker-compose --file docker-compose.test.yml build
@docker-compose --file docker-compose.test.yml run sut
@docker-compose --file docker-compose.test.yml down

## clean: remove binary from non release directory
.PHONY: clean
Expand Down
21 changes: 13 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Stubby
[![Go Report Card](https://goreportcard.com/badge/github.com/davyj0nes/stubby)](https://goreportcard.com/report/github.com/davyj0nes/stubby)
[![Build Status](https://travis-ci.org/DavyJ0nes/stubby.svg?branch=master)](https://travis-ci.org/DavyJ0nes/stubby)
[![Docker Info](https://img.shields.io/badge/docker-info-blue?style=flat&logo=docker)](https://hub.docker.com/repository/docker/davyj0nes/stubby/general)

![Logo](./docs/logo.jpg)

Expand All @@ -9,10 +10,11 @@
- [Description](#description)
- [Usage](#usage)
- [Configuration](#configuration)
- [Basic](#basic)
- [URL Query Params](#url-query-params)
- [Custom Response Headers](#custom-response-headers)
- [Basic](#basic)
- [URL Query Parameters](#url-query-parameters)
- [Custom Response Headers](#custom-response-headers)
- [Docker](#docker)
- [Contributing](#contributing)
- [License](#license)

<!-- vim-markdown-toc -->
Expand All @@ -25,7 +27,7 @@ Return stubbed HTTP responses defined in a config file

### Configuration

### Basic
#### Basic

Add the routes and the responses that you want in the [config file](./comfig.yaml).

Expand All @@ -42,7 +44,7 @@ routes:
}
```
### URL Query Params
#### URL Query Parameters
If the response has URL parameters then these need to be defined as follows:
Expand All @@ -64,7 +66,7 @@ The reason for having them defined in a list rather than as a key/value pair
is due to how the (Queries](https://www.gorillatoolkit.org/pkg/mux#Route.Queries)
method is defined in the router package used ([gorilla mux](https://www.gorillatoolkit.org)).
### Custom Response Headers
#### Custom Response Headers
If you want the response to include a header then you can add it as such:
Expand All @@ -85,9 +87,7 @@ routes:
### Docker
The artifact is stored as a docker image and is located on [Docker Hub](https://hub.docker.com/r/davyj0nes/stubby)
You can also build locally if required by running `make image`.

Run the docker container using `make run_image` in this directory.

```
Expand All @@ -102,6 +102,11 @@ Or you can run the following docker run command anywhere:
docker run --rm -v "$PWD/config.yaml:/bin/config.yaml" -p 8080:8080 davyj0nes/stubby
```
## Contributing
If you would like to contribute to this project then please check out the guidance
within: [CONTRIBUTING.md](./CONTRIBUTING.md)
## License
[MIT](./LICENSE)
Loading

0 comments on commit e1cfc65

Please sign in to comment.