Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
version: 2
updates:
- package-ecosystem: "gomod"
directory: "/"
directories:
- "/"
- "/grpcerrassert"
schedule:
interval: "daily"
commit-message:
Expand Down
21 changes: 15 additions & 6 deletions .github/workflows/go-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,18 @@ permissions: {}

jobs:
build:
name: Build
name: Build (${{ matrix.name }})
runs-on: ubuntu-latest
permissions:
contents: read
strategy:
fail-fast: false
matrix:
include:
- name: errassert
dir: .
- name: grpcerrassert
dir: grpcerrassert
steps:
- uses: actions/checkout@v7

Expand All @@ -31,15 +39,16 @@ jobs:
uses: actions/cache@v6
with:
path: ${{ steps.go-cache-paths.outputs.go-build }}
key: ${{ runner.os }}-gobuild-build-${{ github.sha }}
key: ${{ runner.os }}-gobuild-build-${{ matrix.name }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-gobuild-build
${{ runner.os }}-gobuild-build-${{ matrix.name }}-

- name: Go Mod Cache
uses: actions/cache@v6
with:
path: ${{ steps.go-cache-paths.outputs.go-mod }}
key: ${{ runner.os }}-gomod-build-${{ hashFiles('**/go.sum') }}
key: ${{ runner.os }}-gomod-build-${{ matrix.name }}-${{ hashFiles(format('{0}/go.mod', matrix.dir), format('{0}/go.sum', matrix.dir)) }}

- run: |
go build -v .
- working-directory: ${{ matrix.dir }}
run: |
go build -v ./...
11 changes: 10 additions & 1 deletion .github/workflows/go-lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,18 @@ permissions: {}

jobs:
lint:
name: Lint
name: Lint (${{ matrix.name }})
runs-on: ubuntu-latest
permissions:
contents: read
strategy:
fail-fast: false
matrix:
include:
- name: errassert
dir: .
- name: grpcerrassert
dir: grpcerrassert
steps:
- uses: actions/checkout@v7

Expand All @@ -22,3 +30,4 @@ jobs:
uses: golangci/golangci-lint-action@v9
with:
version: v2.15
working-directory: ${{ matrix.dir }}
21 changes: 16 additions & 5 deletions .github/workflows/go-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,18 @@ permissions: {}

jobs:
test:
name: Test
name: Test (${{ matrix.name }})
runs-on: ubuntu-latest
permissions:
contents: read
strategy:
fail-fast: false
matrix:
include:
- name: errassert
dir: .
- name: grpcerrassert
dir: grpcerrassert
steps:
- uses: actions/checkout@v7

Expand All @@ -32,17 +40,18 @@ jobs:
uses: actions/cache@v6
with:
path: ${{ steps.go-cache-paths.outputs.go-build }}
key: ${{ runner.os }}-gobuild-test-${{ github.sha }}
key: ${{ runner.os }}-gobuild-test-${{ matrix.name }}-${{ github.sha }}
restore-keys: |
${{ runner.os }}-gobuild-test
${{ runner.os }}-gobuild-test-${{ matrix.name }}-

- name: Go Mod Cache
uses: actions/cache@v6
with:
path: ${{ steps.go-cache-paths.outputs.go-mod }}
key: ${{ runner.os }}-gomod-test-${{ hashFiles('**/go.sum') }}
key: ${{ runner.os }}-gomod-test-${{ matrix.name }}-${{ hashFiles(format('{0}/go.mod', matrix.dir), format('{0}/go.sum', matrix.dir)) }}

- run: |
- working-directory: ${{ matrix.dir }}
run: |
go test -v \
-coverprofile=coverage.txt \
-covermode=atomic \
Expand All @@ -54,3 +63,5 @@ jobs:
with:
token: ${{ secrets.CODECOV_TOKEN }}
slug: zoido/errassert
files: ${{ matrix.dir }}/coverage.txt
flags: ${{ matrix.name }}
13 changes: 13 additions & 0 deletions .github/workflows/go.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,16 @@ jobs:
contents: read

secrets: inherit

all-checks-pass:
name: "Go: All Checks Pass"
runs-on: ubuntu-latest
needs: [lint, build, test]
if: always()
permissions: {}
steps:
- env:
NEEDS: ${{ toJSON(needs) }}
run: |
echo "$NEEDS" | jq -r 'to_entries[] | "\(.key): \(.value.result)"'
echo "$NEEDS" | jq -e 'all(.[]; .result == "success")' > /dev/null
3 changes: 2 additions & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
".": "0.5.2"
".": "0.5.2",
"grpcerrassert": "0.5.2"
}
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
- provides similar experience as Testify's [`ErrorAssertionFunc`](https://pkg.go.dev/github.com/stretchr/testify/assert#ErrorAssertionFunc)
- define custom error assertions
- combine assertions with `errassert.Want`
- support assertions for gRPC status errors
- support assertions for gRPC status errors with the separate
[`github.com/zoido/errassert/grpcerrassert`](grpcerrassert) module

## Example

Expand Down
12 changes: 0 additions & 12 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
module github.com/zoido/errassert

go 1.25.0

// 1.55.0 was the 1st version that supported go1.13 error wrapping.
// We want to use the lowest version possible to avoid pushing dependencies to
// clients.
// 1.56.3 is the lowest that is deemed safe by dependabot.
require google.golang.org/grpc v1.83.2

require (
golang.org/x/sys v0.47.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20260526163538-3dc84a4a5aaa // indirect
google.golang.org/protobuf v1.36.11 // indirect
)
71 changes: 71 additions & 0 deletions grpcerrassert/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# `grpcerrassert`: gRPC status error assertions for `errassert`

[![go reference](https://pkg.go.dev/badge/github.com/zoido/errassert/grpcerrassert)](https://pkg.go.dev/github.com/zoido/errassert/grpcerrassert)

This is a separate Go module, so the core [`errassert`](..) module does not
depend on gRPC.

## Example

<!-- markdownlint-disable MD010 MD013 -->

```go
package example_test

import (
"testing"

"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

"github.com/zoido/errassert"
"github.com/zoido/errassert/grpcerrassert"
)

func GetUser(id string) error {
if id == "" {
return status.Error(codes.InvalidArgument, "empty user ID")
}
if id != "42" {
return status.Errorf(codes.NotFound, "user %q not found", id)
}
return nil
}

func TestGetUser(t *testing.T) {
type testCase struct {
id string
errassert errassert.ErrorAssertion
}

run := func(t *testing.T, tc testCase) {
err := GetUser(tc.id)

tc.errassert.Require(t, err)
}

testCases := map[string]testCase{
"ok": {
id: "42",
errassert: errassert.NilError(),
},
"empty ID is invalid argument": {
id: "",
errassert: grpcerrassert.StatusCode(codes.InvalidArgument),
},
"unknown user is not found": {
id: "7",
errassert: errassert.Want(
grpcerrassert.StatusCode(codes.NotFound),
errassert.ErrorContains(`"7"`),
),
},
}

for name, tc := range testCases {
t.Run(name, func(t *testing.T) { run(t, tc) })
}
}
```

<!-- markdownlint-enable MD010 MD013 -->
18 changes: 18 additions & 0 deletions grpcerrassert/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module github.com/zoido/errassert/grpcerrassert

go 1.25.0

require (
github.com/zoido/errassert v1.0.0
google.golang.org/grpc v1.83.2
)

require (
golang.org/x/sys v0.47.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20260526163538-3dc84a4a5aaa // indirect
google.golang.org/protobuf v1.36.11 // indirect
)

// The root module is always developed and tested together with this module.
// Consumers ignore this directive and use the required version instead.
replace github.com/zoido/errassert => ../
File renamed without changes.
13 changes: 11 additions & 2 deletions release-please-config.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
{
"packages": {
".": {
"component": "errassert",
"include-component-in-tag": false,
"changelog-path": "CHANGELOG.md",
"release-type": "go",
"draft-pull-request": true
"exclude-paths": ["grpcerrassert"]
},
"grpcerrassert": {
"component": "grpcerrassert",
"include-component-in-tag": true,
"tag-separator": "/",
"changelog-path": "CHANGELOG.md",
"release-type": "go"
}
},
"pull-request-title-pattern": "chore${scope}: 🔖 release${component} ${version}",
"bump-minor-pre-major": true,
"separate-pull-requests": true,
"draft-pull-request": true,
"bootstrap-sha": "92a5312",
"plugins": [
"sentence-case"
],
Expand Down
Loading