-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit b035d73
Showing
11 changed files
with
357 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
name: lint | ||
on: | ||
push: | ||
tags: | ||
- v* | ||
branches: | ||
- master | ||
- main | ||
pull_request: | ||
jobs: | ||
golangci: | ||
name: golangci-lint | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: golangci-lint | ||
uses: golangci/[email protected] | ||
with: | ||
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version. | ||
version: v1.42.0 | ||
|
||
# Optional: working directory, useful for monorepos | ||
# working-directory: somedir | ||
|
||
# Optional: golangci-lint command line arguments. | ||
# args: --issues-exit-code=0 | ||
|
||
# Optional: show only new issues if it's a pull request. The default value is `false`. | ||
# only-new-issues: true | ||
|
||
# Optional: if set to true then the action will use pre-installed Go. | ||
# skip-go-installation: true | ||
|
||
# Optional: if set to true then the action don't cache or restore ~/go/pkg. | ||
# skip-pkg-cache: true | ||
|
||
# Optional: if set to true then the action don't cache or restore ~/.cache/go-build. | ||
# skip-build-cache: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
name: test | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
pull_request: | ||
|
||
env: | ||
GO111MODULE: "on" | ||
GO_LATEST_VERSION: "1.17.x" | ||
|
||
jobs: | ||
test: | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
os: [ ubuntu-latest, macos-latest ] | ||
go-version: [ 1.16.x, 1.17.x ] | ||
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: Go cache | ||
uses: actions/cache@v2 | ||
with: | ||
# In order: | ||
# * Module download cache | ||
# * Build cache (Linux) | ||
path: | | ||
~/go/pkg/mod | ||
~/.cache/go-build | ||
key: ${{ runner.os }}-go-${{ matrix.go-version }}-cache-${{ hashFiles('**/go.sum') }} | ||
restore-keys: | | ||
${{ runner.os }}-go-${{ matrix.go-version }}-cache | ||
- name: Test | ||
id: test | ||
run: | | ||
make test | ||
- name: Upload code coverage (unit) | ||
if: matrix.go-version == env.GO_LATEST_VERSION | ||
uses: codecov/codecov-action@v1 | ||
with: | ||
file: ./unit.coverprofile | ||
flags: unittests-${{ runner.os }} | ||
|
||
# - name: Upload code coverage (features) | ||
# if: matrix.go-version == env.GO_LATEST_VERSION | ||
# uses: codecov/codecov-action@v1 | ||
# with: | ||
# file: ./features.coverprofile | ||
# flags: featurestests-${{ runner.os }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Binaries for programs and plugins | ||
*.exe | ||
*.exe~ | ||
*.dll | ||
*.so | ||
*.dylib | ||
|
||
# Test binary, built with `go test -c` | ||
*.test | ||
|
||
# Output of the go coverage tool, specifically when used with LiteIDE | ||
*.out | ||
|
||
# Dependency directories (remove the comment below to include it) | ||
/vendor | ||
|
||
*.coverprofile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# See https://github.com/golangci/golangci-lint/blob/master/.golangci.example.yml | ||
run: | ||
tests: true | ||
|
||
linters-settings: | ||
errcheck: | ||
check-type-assertions: true | ||
check-blank: true | ||
gocyclo: | ||
min-complexity: 20 | ||
dupl: | ||
threshold: 100 | ||
misspell: | ||
locale: US | ||
unused: | ||
check-exported: false | ||
unparam: | ||
check-exported: true | ||
|
||
linters: | ||
enable-all: true | ||
disable: | ||
- exhaustivestruct | ||
- forbidigo | ||
- forcetypeassert | ||
- gci | ||
- gochecknoglobals | ||
- gomnd | ||
- ifshort | ||
- interfacer | ||
- lll | ||
- maligned | ||
- paralleltest | ||
- scopelint | ||
- testpackage | ||
- wrapcheck | ||
|
||
issues: | ||
exclude-use-default: false | ||
exclude-rules: | ||
- linters: | ||
- dupl | ||
- funlen | ||
- goconst | ||
- goerr113 | ||
- gomnd | ||
- noctx | ||
path: "_test.go" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2021 Nhat | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
VENDOR_DIR = vendor | ||
|
||
GO ?= go | ||
GOLANGCI_LINT ?= golangci-lint | ||
|
||
.PHONY: $(VENDOR_DIR) lint test test-unit | ||
|
||
$(VENDOR_DIR): | ||
@mkdir -p $(VENDOR_DIR) | ||
@$(GO) mod vendor | ||
@$(GO) mod tidy | ||
|
||
lint: | ||
@$(GOLANGCI_LINT) run | ||
|
||
test: test-unit | ||
|
||
## Run unit tests | ||
test-unit: | ||
@echo ">> unit test" | ||
@$(GO) test -gcflags=-l -coverprofile=unit.coverprofile -covermode=atomic -race ./... | ||
|
||
#test-integration: | ||
# @echo ">> integration test" | ||
# @$(GO) test ./features/... -gcflags=-l -coverprofile=features.coverprofile -coverpkg ./... -race --godog |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# @nhatthm/{name} | ||
|
||
<!-- | ||
[![GitHub Releases](https://img.shields.io/github/v/release/nhatthm/{name})](https://github.com/nhatthm/{name}/releases/latest) | ||
[![Build Status](https://github.com/nhatthm/{name}/actions/workflows/test.yaml/badge.svg)](https://github.com/nhatthm/{name}/actions/workflows/test.yaml) | ||
[![codecov](https://codecov.io/gh/nhatthm/{name}/branch/master/graph/badge.svg?token=eTdAgDE2vR)](https://codecov.io/gh/nhatthm/{name}) | ||
[![Go Report Card](https://goreportcard.com/badge/github.com/nhatthm/{name})](https://goreportcard.com/report/github.com/nhatthm/{name}) | ||
[![GoDevDoc](https://img.shields.io/badge/dev-doc-00ADD8?logo=go)](https://pkg.go.dev/github.com/nhatthm/{name}) | ||
[![Donate](https://img.shields.io/badge/Donate-PayPal-green.svg)](https://www.paypal.com/donate/?hosted_button_id=PJZSGJN57TDJY) | ||
--> | ||
|
||
TBD | ||
|
||
## Prerequisites | ||
|
||
- `Go >= 1.15` | ||
|
||
## Install | ||
|
||
```bash | ||
go get github.com/nhatthm/{name} | ||
``` | ||
|
||
## Usage | ||
|
||
TBD | ||
|
||
## Examples | ||
|
||
TBA | ||
|
||
## Donation | ||
|
||
If this project help you reduce time to develop, you can give me a cup of coffee :) | ||
|
||
### Paypal donation | ||
|
||
[![paypal](https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif)](https://www.paypal.com/donate/?hosted_button_id=PJZSGJN57TDJY) | ||
|
||
or scan this | ||
|
||
<img src="https://user-images.githubusercontent.com/1154587/113494222-ad8cb200-94e6-11eb-9ef3-eb883ada222a.png" width="147px" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ignore: | ||
- "features/**/*" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// Package main | ||
package main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package cucumber | ||
|
||
import ( | ||
"bytes" | ||
"flag" | ||
"fmt" | ||
"io/ioutil" | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/cucumber/godog" | ||
"github.com/spf13/pflag" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
// Used by init(). | ||
// | ||
//nolint:gochecknoglobals | ||
var ( | ||
runGoDogTests bool | ||
|
||
out = new(bytes.Buffer) | ||
opt = godog.Options{ | ||
Strict: true, | ||
Output: out, | ||
} | ||
) | ||
|
||
// This has to run on init to define -godog flag, otherwise "undefined flag" error happens. | ||
// | ||
//nolint:gochecknoinits | ||
func init() { | ||
flag.BoolVar(&runGoDogTests, "godog", false, "Set this flag is you want to run godog BDD tests") | ||
godog.BindCommandLineFlags("godog.", &opt) | ||
} | ||
|
||
func TestMain(m *testing.M) { | ||
flag.Parse() | ||
pflag.Parse() | ||
|
||
os.Exit(m.Run()) | ||
} | ||
|
||
func TestIntegration(t *testing.T) { | ||
if !runGoDogTests { | ||
t.Skip(`Missing "--godog" flag, skipping integration test.`) | ||
} | ||
|
||
RunSuite(t, "..", func(t *testing.T, ctx *godog.ScenarioContext) { | ||
t.Helper() | ||
}) | ||
} | ||
|
||
func RunSuite(t *testing.T, path string, featureContext func(t *testing.T, ctx *godog.ScenarioContext)) { | ||
t.Helper() | ||
|
||
var paths []string | ||
|
||
files, err := ioutil.ReadDir(filepath.Clean(path)) | ||
assert.NoError(t, err) | ||
|
||
paths = make([]string, 0, len(files)) | ||
|
||
for _, f := range files { | ||
if strings.HasSuffix(f.Name(), ".feature") { | ||
paths = append(paths, filepath.Join(path, f.Name())) | ||
} | ||
} | ||
|
||
for _, path := range paths { | ||
path := path | ||
|
||
t.Run(path, func(t *testing.T) { | ||
opt.Paths = []string{path} | ||
suite := godog.TestSuite{ | ||
Name: "Integration", | ||
TestSuiteInitializer: nil, | ||
ScenarioInitializer: func(s *godog.ScenarioContext) { | ||
featureContext(t, s) | ||
}, | ||
Options: &opt, | ||
} | ||
status := suite.Run() | ||
|
||
if status != 0 { | ||
fmt.Println(out.String()) | ||
assert.Failf(t, "one or more scenarios failed in feature: %s", path) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module github.com/nhatthm/template-go-project | ||
|
||
go 1.17 | ||
|
||
require ( | ||
github.com/cucumber/godog v0.11.0 | ||
github.com/spf13/pflag v1.0.5 | ||
github.com/stretchr/testify v1.7.0 | ||
) |