Skip to content

Commit a4a8bd6

Browse files
authored
Merge pull request #76 from ViktorTigerstrom/2023-05-export-hashmail-harness
itest: export HashmailHarness struct
2 parents b0ee139 + 85f5f04 commit a4a8bd6

File tree

4 files changed

+77
-26
lines changed

4 files changed

+77
-26
lines changed

.golangci.yml

+51-8
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@ linters-settings:
1818
gofmt:
1919
# simplify code: gofmt with `-s` option, true by default
2020
simplify: true
21+
funlen:
22+
# Checks the number of lines in a function.
23+
# If lower than 0, disable the check.
24+
lines: 200
25+
# Checks the number of statements in a function.
26+
statements: 80
27+
gosec:
28+
excludes:
29+
- G402 # Look for bad TLS connection settings.
30+
- G306 # Poor file permissions used when writing to a new file.
2131

2232
linters:
2333
enable-all: true
@@ -32,16 +42,49 @@ linters:
3242
# them even longer by marking them as 'nolint'.
3343
- lll
3444

35-
# We don't care (enough) about misaligned structs to lint that.
36-
- maligned
37-
38-
# We have long functions, especially in tests. Moving or renaming those
39-
# would trigger funlen problems that we may not want to solve at that time.
40-
- funlen
45+
# We don't require that all structs have all fields initialized when new
46+
# instances are created.
47+
- exhaustruct
4148

42-
# Gosec is outdated and reports false positives.
43-
- gosec
49+
# Deprecated linters. See https://golangci-lint.run/usage/linters/.
50+
- interfacer
51+
- golint
52+
- maligned
53+
- scopelint
54+
- exhaustivestruct
55+
- bodyclose
56+
- contextcheck
57+
- nilerr
58+
- noctx
59+
- rowserrcheck
60+
- sqlclosecheck
61+
- structcheck
62+
- tparallel
63+
- unparam
64+
- wastedassign
65+
- ifshort
66+
- varcheck
67+
- deadcode
68+
- nosnakecase
4469

4570
issues:
4671
# Only show newly introduced problems.
4772
new-from-rev: 4008b92d81d4d62e663025c5f79ebe44b53f283c
73+
74+
exclude-rules:
75+
# Exclude gosec from running for tests so that tests with weak randomness
76+
# (math/rand) will pass the linter. We also exclude funlen from tests as
77+
# have test functions that are intentionally long.
78+
- path: _test\.go
79+
linters:
80+
- gosec
81+
- funlen
82+
83+
- path: test*
84+
linters:
85+
- gosec
86+
- funlen
87+
88+
- path: itest/.*
89+
linters:
90+
- paralleltest

itest/connection_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,14 @@ func testHashmailServerReconnect(t *harnessTest) {
4545
require.Equal(t.t, len(defaultMessage)*10, len(resp.Resp))
4646

4747
// Shut down hashmail server
48-
require.NoError(t.t, t.hmserver.stop())
48+
require.NoError(t.t, t.hmserver.Stop())
4949

5050
// Check that the client and server status are updated appropriately.
5151
assertServerStatus(t, mailbox.ServerStatusNotConnected)
5252
assertClientStatus(t, mailbox.ClientStatusNotConnected)
5353

5454
// Restart hashmail server
55-
require.NoError(t.t, t.hmserver.start())
55+
require.NoError(t.t, t.hmserver.Start())
5656

5757
// Check that the client and server successfully reconnect.
5858
assertServerStatus(t, mailbox.ServerStatusInUse)

itest/hashmailserver_harness.go

+16-11
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,17 @@ import (
1212
"github.com/lightningnetwork/lnd/lntest/wait"
1313
)
1414

15-
type hashmailHarness struct {
16-
aperture *aperture.Aperture
17-
apertureCfg *aperture.Config
15+
type HashmailHarness struct {
16+
aperture *aperture.Aperture
17+
18+
// ApertureCfg is the configuration aperture uses when being initialized.
19+
ApertureCfg *aperture.Config
1820
}
1921

20-
func newHashmailHarness() *hashmailHarness {
21-
return &hashmailHarness{
22-
apertureCfg: &aperture.Config{
22+
// NewHashmailHarness creates a new instance of the HashmailHarness.
23+
func NewHashmailHarness() *HashmailHarness {
24+
return &HashmailHarness{
25+
ApertureCfg: &aperture.Config{
2326
ListenAddr: fmt.Sprintf("127.0.0.1:%d",
2427
node.NextAvailablePort()),
2528
Authenticator: &aperture.AuthConfig{
@@ -39,8 +42,8 @@ func newHashmailHarness() *hashmailHarness {
3942
}
4043

4144
// initAperture starts the aperture proxy.
42-
func (hm *hashmailHarness) initAperture() error {
43-
hm.aperture = aperture.NewAperture(hm.apertureCfg)
45+
func (hm *HashmailHarness) initAperture() error {
46+
hm.aperture = aperture.NewAperture(hm.ApertureCfg)
4447
errChan := make(chan error)
4548

4649
if err := hm.aperture.Start(errChan); err != nil {
@@ -60,7 +63,7 @@ func (hm *hashmailHarness) initAperture() error {
6063
}
6164
return wait.NoError(func() error {
6265
apertureAddr := fmt.Sprintf("https://%s/dummy",
63-
hm.apertureCfg.ListenAddr)
66+
hm.ApertureCfg.ListenAddr)
6467

6568
resp, err := http.Get(apertureAddr)
6669
if err != nil {
@@ -75,14 +78,16 @@ func (hm *hashmailHarness) initAperture() error {
7578
}, 3*time.Second)
7679
}
7780

78-
func (hm *hashmailHarness) start() error {
81+
// Start attempts to start the aperture proxy.
82+
func (hm *HashmailHarness) Start() error {
7983
if err := hm.initAperture(); err != nil {
8084
return fmt.Errorf("could not start aperture: %v", err)
8185
}
8286

8387
return nil
8488
}
8589

86-
func (hm *hashmailHarness) stop() error {
90+
// Stop attempts to stop the aperture proxy.
91+
func (hm *HashmailHarness) Stop() error {
8792
return hm.aperture.Stop()
8893
}

itest/test_harness.go

+8-5
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ type harnessTest struct {
4444

4545
server *serverHarness
4646

47-
hmserver *hashmailHarness
47+
hmserver *HashmailHarness
4848
}
4949

5050
// testConfig determines the way in which the test will be set up.
@@ -60,12 +60,15 @@ func newHarnessTest(t *testing.T, cfg *testConfig) *harnessTest {
6060

6161
mailboxAddr := testnetMailbox
6262
var insecure bool
63+
6364
if !cfg.stagingMailbox {
64-
ht.hmserver = newHashmailHarness()
65-
if err := ht.hmserver.start(); err != nil {
65+
ht.hmserver = NewHashmailHarness()
66+
67+
if err := ht.hmserver.Start(); err != nil {
6668
t.Fatalf("could not start hashmail server: %v", err)
6769
}
68-
mailboxAddr = ht.hmserver.apertureCfg.ListenAddr
70+
71+
mailboxAddr = ht.hmserver.ApertureCfg.ListenAddr
6972
insecure = true
7073
}
7174

@@ -186,7 +189,7 @@ func (h *harnessTest) shutdown() error {
186189
h.server.stop()
187190

188191
if h.hmserver != nil {
189-
err := h.hmserver.stop()
192+
err := h.hmserver.Stop()
190193
if err != nil {
191194
returnErr = err
192195
}

0 commit comments

Comments
 (0)