Skip to content

Commit bcd596e

Browse files
committed
Make/itest: enable coverage output for tests and itests
1 parent 6386792 commit bcd596e

File tree

5 files changed

+55
-12
lines changed

5 files changed

+55
-12
lines changed

.github/workflows/docker-test.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,20 @@ jobs:
1616

1717
- name: Run tests in docker container
1818
run: make docker-test-all
19+
20+
- name: Upload unit test coverage
21+
uses: shogo82148/actions-goveralls@v1
22+
with:
23+
path-to-profile: cover.out
24+
parallel: true
25+
26+
- name: Upload integration test coverage
27+
uses: shogo82148/actions-goveralls@v1
28+
with:
29+
path-to-profile: icover.out
30+
parallel: true
31+
32+
- name: Generate coverage badge
33+
uses: shogo82148/actions-goveralls@v1
34+
with:
35+
parallel-finished: true

Makefile

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
.PHONY: docker docker-itest docker-test docker-test-all docker-check docker-shell itest test test-all
1+
.PHONY: cover docker docker-itest docker-test docker-test-all docker-check docker-shell itest test test-all
22

3-
IMG_NAME := lndsigner-builder
3+
IMG_NAME := lndsigner-builder
44

55
CPLATFORM := $(shell uname -m)
66

7+
GOCOVERDIR := /tmp/lndsigner-icover-$(shell date +%s)
8+
79
ifeq ($(CPLATFORM), x86_64)
810
GOPLATFORM := amd64
911
endif
@@ -55,11 +57,18 @@ docker-shell: docker
5557
--mount type=bind,source=$(CURDIR),target=/app $(IMG_NAME):latest \
5658
bash -l
5759

58-
itest:
59-
go install -race -buildvcs=false ./cmd/... && go test -v -count=1 -race -tags=itest -cover ./itest
60+
cover:
61+
mkdir $(GOCOVERDIR) && mkdir $(GOCOVERDIR)/lndsignerd && \
62+
mkdir $(GOCOVERDIR)/plugin && mkdir $(GOCOVERDIR)/combined
63+
64+
itest: cover
65+
go install -race -cover -buildvcs=false ./cmd/... && \
66+
GOCOVERDIR=$(GOCOVERDIR) go test -v -count=1 -race -tags=itest ./itest && \
67+
go tool covdata merge -pcombine -i=$(GOCOVERDIR)/lndsignerd,$(GOCOVERDIR)/plugin -o=$(GOCOVERDIR)/combined && \
68+
go tool covdata textfmt -i=$(GOCOVERDIR)/combined -o icover.out && \
69+
rm -rf $(GOCOVERDIR)
6070

6171
test:
62-
go test -v -count=1 -race -cover ./...
72+
go test -v -count=1 -race -coverprofile cover.out ./...
6373

64-
test-all:
65-
go install -race -buildvcs=false ./cmd/... && go test -v -count=1 -race -tags=itest -cover ./...
74+
test-all: test itest

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
[![Coverage Status](https://coveralls.io/repos/github/NYDIG-OSS/lndsigner/badge.svg?branch=main)](https://coveralls.io/github/NYDIG-OSS/lndsigner?branch=main)
2+
13
# lndsigner
24
`lndsigner` is a [remote signer](https://github.com/lightningnetwork/lnd/blob/master/docs/remote-signing.md) for [lnd](https://github.com/lightningnetwork/lnd). Currently, it can do the following:
35
- [x] store seeds for multiple nodes in [Hashicorp Vault](https://github.com/hashicorp/vault/)

itest/itest_context_test.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ type testContext struct {
3535
vaultPort string
3636
vaultCmd *exec.Cmd
3737
vaultClient *api.Logical
38+
vaultSys *api.Sys
3839

3940
bitcoinDir string
4041
bitcoinRPC string
@@ -137,6 +138,11 @@ func newTestContext(t *testing.T) *testContext {
137138
"-dev-root-token-id=root", "-dev-plugin-dir="+pluginDir,
138139
"-dev-listen-address=127.0.0.1:"+tctx.vaultPort)
139140

141+
tctx.vaultCmd.Env = append(tctx.vaultCmd.Env,
142+
"PATH="+os.Getenv("PATH"),
143+
"GOCOVERDIR="+path.Join(os.Getenv("GOCOVERDIR"), "plugin"),
144+
)
145+
140146
go waitProc(tctx.vaultCmd)
141147

142148
vaultClientConf := api.DefaultConfig()
@@ -148,9 +154,9 @@ func newTestContext(t *testing.T) *testContext {
148154
vaultClient.SetToken("root")
149155

150156
tctx.vaultClient = vaultClient.Logical()
157+
tctx.vaultSys = vaultClient.Sys()
151158

152-
vaultSys := vaultClient.Sys()
153-
err = vaultSys.Mount("lndsigner", &api.MountInput{
159+
err = tctx.vaultSys.Mount("lndsigner", &api.MountInput{
154160
Type: "vault-plugin-lndsigner",
155161
})
156162
require.NoError(t, err)
@@ -213,6 +219,7 @@ func (tctx *testContext) Close() {
213219
lnd.Close()
214220
}
215221

222+
_ = tctx.vaultSys.Unmount("lndsigner")
216223
_ = tctx.bitcoinCli("stop")
217224
_ = tctx.vaultCmd.Process.Signal(os.Interrupt)
218225

itest/itest_lndharness_test.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ import (
1414
"encoding/json"
1515
"encoding/pem"
1616
"fmt"
17-
"github.com/nydig-oss/lndsigner"
18-
"github.com/nydig-oss/lndsigner/itest"
1917
"io/fs"
2018
"math/big"
2119
"net"
@@ -25,6 +23,9 @@ import (
2523
"testing"
2624
"time"
2725

26+
"github.com/nydig-oss/lndsigner"
27+
"github.com/nydig-oss/lndsigner/itest"
28+
2829
"github.com/stretchr/testify/require"
2930
"go.uber.org/zap"
3031
"go.uber.org/zap/zapcore"
@@ -95,8 +96,13 @@ func (l *lndHarness) Start() {
9596
l.lndSignerCmd.Env = append(l.lndSignerCmd.Env,
9697
"VAULT_ADDR=http://127.0.0.1:"+l.tctx.vaultPort,
9798
"VAULT_TOKEN=root",
99+
"GOCOVERDIR="+path.Join(os.Getenv("GOCOVERDIR"), "lndsignerd"),
98100
)
99101

102+
l.lndSignerCmd.Cancel = func() error {
103+
return l.lndSignerCmd.Process.Signal(os.Interrupt)
104+
}
105+
100106
go waitProc(l.lndSignerCmd)
101107

102108
// Start lnd.
@@ -265,7 +271,9 @@ func waitFile(t *testing.T, file, waitStr string) {
265271
// exit error, the program's entire stderr and stdout are logged.
266272
func waitProc(cmd *exec.Cmd) {
267273
output, err := cmd.CombinedOutput()
268-
if err != nil && err.Error() != "signal: killed" {
274+
if err != nil && err.Error() != "signal: killed" &&
275+
err != context.Canceled {
276+
269277
config := zap.NewDevelopmentConfig()
270278
config.EncoderConfig.EncodeLevel = zapcore.CapitalColorLevelEncoder
271279
config.EncoderConfig.EncodeCaller = nil

0 commit comments

Comments
 (0)