Skip to content

Commit

Permalink
Merge pull request #12 from oxyno-zeta/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
oxyno-zeta authored Dec 31, 2021
2 parents b925318 + f5254d2 commit fbaa819
Show file tree
Hide file tree
Showing 11 changed files with 364 additions and 59 deletions.
46 changes: 0 additions & 46 deletions .circleci/config.yml

This file was deleted.

48 changes: 48 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: ci
on:
push:
branches-ignore:
- "github-pages"
pull_request: {}
jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: golangci/golangci-lint-action@v2
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: v1.43.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
test:
runs-on: ubuntu-latest
needs:
- lint
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: "^1.17.0"
- run: make test/unit
- run: make test/coverage
- run: go get github.com/mattn/goveralls
- env:
COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: goveralls -coverprofile=c.out -service=github
18 changes: 14 additions & 4 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -330,26 +330,22 @@ linters:
- typecheck
- bodyclose
- noctx
- golint
- rowserrcheck
- stylecheck
- gosec
- interfacer
- unconvert
- dupl
- goconst
- asciicheck
- gofmt
- goimports
- goheader
- maligned
- depguard
- misspell
- lll
- unparam
- dogsled
- nakedret
- scopelint
- gocritic
- gochecknoinits
- godox
Expand All @@ -364,6 +360,17 @@ linters:
- sqlclosecheck
- nlreturn
- nolintlint
- forcetypeassert
- gomoddirectives
- importas
- nilerr
- promlinter
- revive
- wastedassign
- bidichk
- contextcheck
- nilnil
- tenv
disable:
- prealloc
- gochecknoglobals
Expand All @@ -375,6 +382,9 @@ linters:
- gci
- goerr113 # Forbid dynamic errors
- nestif
- scopelint
- ireturn
- varnamelen
disable-all: false
presets:
- bugs
Expand Down
51 changes: 51 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/commitizen-tools/commitizen
rev: v2.20.0
hooks:
- id: commitizen
stages: [commit-msg]
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
hooks:
- id: check-json
stages: [commit]
- id: check-merge-conflict
stages: [commit]
- id: trailing-whitespace
stages: [commit]
- id: end-of-file-fixer
stages: [commit]
- id: check-yaml
stages: [commit]
- id: check-added-large-files
stages: [commit]
- id: check-executables-have-shebangs
stages: [commit]
- id: detect-aws-credentials
stages: [commit]
- id: detect-private-key
stages: [commit]
- repo: https://github.com/pre-commit/mirrors-prettier
# Use the sha or branch you want to point at
rev: v2.4.1
hooks:
- id: prettier
stages: [commit]
- repo: https://github.com/shellcheck-py/shellcheck-py
rev: v0.8.0.1
hooks:
- id: shellcheck
stages: [commit]
- repo: local
hooks:
- id: backend-lint
stages: [commit]
files: \.go$
name: Backend Lint
entry: make
args:
- code/lint
require_serial: true
language: system
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ ifndef HAS_GOLANGCI_LINT
ifndef HAS_CURL
$(error You must install curl)
endif
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell go env GOPATH)/bin v1.30.0
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell go env GOPATH)/bin v1.43.0
endif
ifndef HAS_GIT
$(error You must install Git)
Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,18 @@ type Fake struct {
mock.EXPECT().DoSomething(extra.StructMatcher().Field("Name", "value1").Field("Data", gomock.Eq(map[string]string{"fake":"value"})))
```

### OrMatcher

#### Explanation

This matcher will allow to test multiple matchers with a logical "OR" between them. This will stop at first match.

#### Example

```go
mock.EXPECT().DoSomething(extra.OrMatcher(gomock.Eq(1), gomock.Eq(10), gomock.Eq(15)))
```

## Thanks

- My wife BH to support me doing this
Expand Down
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
github.com/golang/mock v1.4.4 h1:l75CXGRSwbaYNpl/Z2X1XIIAMSCquvXgpVZDhwEIJsc=
github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4=
github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
Expand All @@ -21,7 +18,6 @@ golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9sn
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
6 changes: 3 additions & 3 deletions map-matcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,11 @@ func (m *mapMatcher) Matches(x interface{}) bool {
// Store if matcher key can be found
matchKeyFound := false
// Loop over map keys
for _, kVal := range rval.MapKeys() {
for _, keyVal := range rval.MapKeys() {
// Get key data
keyD := kVal.Interface()
keyD := keyVal.Interface()
// Get reflect value from key
rv := rval.MapIndex(kVal)
rv := rval.MapIndex(keyVal)
// Get data from key
val := rv.Interface()
// Check if matcher key is matching current key
Expand Down
58 changes: 58 additions & 0 deletions or-matcher.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package extra

import (
"fmt"

"github.com/golang/mock/gomock"
)

type orMatcher struct {
matchers []gomock.Matcher
}

func (om *orMatcher) String() string {
if len(om.matchers) == 0 {
return "the \"or\" matcher will return false because list is empty"
}

// Initialize string
str := ""

// Loop over matchers
for i, m := range om.matchers {
// Ignore the first item
if i > 0 {
str += " or "
}

// Concat matcher string
str += fmt.Sprintf("(%s)", m.String())
}

return str
}

func (om *orMatcher) Matches(x interface{}) bool {
// Check empty case
if len(om.matchers) == 0 {
return false
}

// Loop over matchers
for _, m := range om.matchers {
// Check if matcher is ok
if m.Matches(x) {
// Matches so ... End
return true
}
}

// No match until now
// Or is false
return false
}

// OrMatcher will return a new Or matcher.
func OrMatcher(matchers ...gomock.Matcher) gomock.Matcher {
return &orMatcher{matchers: matchers}
}
Loading

0 comments on commit fbaa819

Please sign in to comment.