Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mock: Add mockgen workflow #313

Merged
merged 2 commits into from
Nov 16, 2021
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
19 changes: 19 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,25 @@ jobs:

- name: run check
run: make rpc-check

############################
# Mock generation and check
############################
mockgen-check:
name: Mockgen check
runs-on: ubuntu-latest
steps:
- name: git checkout
uses: actions/checkout@v2

- name: docker image cache
uses: satackey/action-docker-layer-caching@v0.0.11

- name: Generate mocks
run: make gen

- name: run check
run: make mock-check

########################
# lint code
Expand Down
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,16 @@ list:
grep -v Makefile | \
sort

gen: rpc mock

mock:
@$(call print, "Generating mock packages.")
cd ./gen; ./gen_mock_docker.sh

mock-check: mock
@$(call print, "Verifying mocks.")
if test -n "$$(git status --porcelain '*.go')"; then echo "Mocks not properly generated!"; git status --porcelain '*.go'; exit 1; fi

rpc:
@$(call print, "Compiling protos.")
cd ./poolrpc; ./gen_protos_docker.sh
Expand Down
9 changes: 9 additions & 0 deletions gen.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package pool

// This program generates mocks. It can be invoked by running:
//
// make mock
//

//go:generate mockgen -source=sidecar/interfaces.go -package=sidecar -destination=sidecar/mock_interfaces.go
//go:generate mockgen -source=internal/test/interfaces.go -package=test -destination=internal/test/mock_interfaces.go
7 changes: 7 additions & 0 deletions gen/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM golang:1.17.1-bullseye

RUN go install github.com/golang/mock/mockgen@v1.6.0

WORKDIR /build

CMD ["/bin/bash", "-c", "go generate ./..."]
24 changes: 24 additions & 0 deletions gen/gen_mock_docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

set -e

# Directory of the script file, independent of where it's called from.
DIR="$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)"
# Use the user's cache directories
GOCACHE=`go env GOCACHE`
GOMODCACHE=`go env GOMODCACHE`

echo "Building mockgen docker image..."
docker build -t pool-gen-builder .

echo "Generating and formatting mock files..."
docker run \
--rm \
--user "$UID:$(id -g)" \
-e UID=$UID \
-e GOCACHE=$GOCACHE \
-e GOMODCACHE=$GOMODCACHE \
-v "$GOCACHE:$GOCACHE" \
-v "$GOMODCACHE:$GOMODCACHE" \
-v "$DIR/../:/build" \
pool-gen-builder
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ require (
github.com/btcsuite/btcwallet/wallet/txrules v1.1.0
github.com/btcsuite/btcwallet/wtxmgr v1.3.1-0.20210822222949-9b5a201c344c
github.com/davecgh/go-spew v1.1.1
github.com/golang/mock v1.6.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.5.0
github.com/jessevdk/go-flags v1.4.0
github.com/lightninglabs/aperture v0.1.6-beta
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ github.com/golang/mock v1.4.0/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt
github.com/golang/mock v1.4.1/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw=
github.com/golang/mock v1.4.3/go.mod h1:UOMv5ysSaYNkG+OFQykRIcU/QvvxJf3p21QfJ2Bt3cw=
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/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
Expand Down Expand Up @@ -963,6 +965,7 @@ golang.org/x/tools v0.0.0-20200729194436-6467de6f59a7/go.mod h1:njjCfa9FT2d7l9Bc
golang.org/x/tools v0.0.0-20200804011535-6c149bb5ef0d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
golang.org/x/tools v0.0.0-20200825202427-b303f430e36d/go.mod h1:njjCfa9FT2d7l9Bc6FUM5FLjQPp3cFF28FI3qnDFljA=
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.2/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.3 h1:L69ShwSZEyCsLKoAxDKeMvLDZkumEe8gXUZAjab0tX8=
golang.org/x/tools v0.1.3/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
Expand Down
11 changes: 11 additions & 0 deletions internal/test/interfaces.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package test

import "github.com/lightninglabs/lndclient"

type SignerClient interface {
lndclient.SignerClient
}

type WalletKitClient interface {
lndclient.WalletKitClient
}
Loading