Skip to content

Commit 30a57a4

Browse files
committed
make+gh: run unit tests
1 parent ca1d793 commit 30a57a4

File tree

3 files changed

+65
-3
lines changed

3 files changed

+65
-3
lines changed

.github/workflows/main.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- "master"
7+
pull_request:
8+
branches:
9+
- "*"
10+
11+
defaults:
12+
run:
13+
shell: bash
14+
15+
env:
16+
# go needs absolute directories, using the $HOME variable doesn't work here.
17+
GOCACHE: /home/runner/work/go/pkg/build
18+
GOPATH: /home/runner/work/go
19+
GO_VERSION: 1.22.3
20+
21+
jobs:
22+
########################
23+
# run unit tests
24+
########################
25+
unit-test:
26+
name: run unit tests
27+
runs-on: ubuntu-latest
28+
steps:
29+
- name: git checkout
30+
uses: actions/checkout@v3
31+
32+
- name: go cache
33+
uses: actions/cache@v3
34+
with:
35+
path: /home/runner/work/go
36+
key: btclog-${{ runner.os }}-go-${{ env.GO_VERSION }}-${{ github.job }}-${{ hashFiles('**/go.sum') }}
37+
restore-keys: |
38+
btclog-${{ runner.os }}-go-${{ env.GO_VERSION }}-${{ github.job }}-${{ hashFiles('**/go.sum') }}
39+
btclog-${{ runner.os }}-go-${{ env.GO_VERSION }}-${{ github.job }}-
40+
btclog-${{ runner.os }}-go-${{ env.GO_VERSION }}-
41+
btclog-${{ runner.os }}-go-
42+
43+
- name: setup go ${{ env.GO_VERSION }}
44+
uses: actions/setup-go@v3
45+
with:
46+
go-version: '~${{ env.GO_VERSION }}'
47+
48+
- name: run unit tests
49+
run: make unit

Makefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
PKG := github.com/lightninglabs/btclog
2+
3+
GOLIST := go list -deps $(PKG)/... | grep '$(PKG)'| grep -v '/vendor/'
4+
GOTEST := go test -v
5+
6+
XARGS := xargs -L 1
7+
UNIT := $(GOLIST) | $(XARGS) env $(GOTEST) $(TEST_FLAGS)
8+
9+
unit:
10+
@$(call print, "Running unit tests.")
11+
$(UNIT)

handler_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ func TestDefaultHandler(t *testing.T) {
3737
log.Debugf("Test basic log with %s", "format")
3838
log.Trace("Log should not appear due to level")
3939
},
40-
expectedLog: `1970-01-01 02:01:40.000 [INF]: Test Basic Log
41-
1970-01-01 02:01:40.000 [DBG]: Test basic log with format
40+
expectedLog: `1970-01-01 09:01:40.000 [INF]: Test Basic Log
41+
1970-01-01 09:01:40.000 [DBG]: Test basic log with format
4242
`,
4343
},
4444
{
@@ -145,7 +145,9 @@ func TestDefaultHandler(t *testing.T) {
145145
test.logFunc(NewSLogger(handler))
146146

147147
if string(buf.Bytes()) != test.expectedLog {
148-
t.Fatalf("Log result mismatch. Expected \n\"%s\", got \n\"%s\"", test.expectedLog, buf.Bytes())
148+
t.Fatalf("Log result mismatch. Expected "+
149+
"\n\"%s\", got \n\"%s\"",
150+
test.expectedLog, buf.Bytes())
149151
}
150152
})
151153
}

0 commit comments

Comments
 (0)