From 21cb04739a647034a7a49f08b04ff66630e45da5 Mon Sep 17 00:00:00 2001 From: Chris Quigley Date: Wed, 2 Sep 2026 16:00:07 -0400 Subject: [PATCH 1/2] First pass --- internal/db/p2p.go | 3 +++ internal/db/p2p_test.go | 27 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 internal/db/p2p_test.go diff --git a/internal/db/p2p.go b/internal/db/p2p.go index 573c77d677..599b8e2a89 100644 --- a/internal/db/p2p.go +++ b/internal/db/p2p.go @@ -59,6 +59,9 @@ func (db *DB) Connect( return err } + if db.p2p == nil { + return ErrNoP2P + } return db.p2p.Connect(ctx, addresses) } diff --git a/internal/db/p2p_test.go b/internal/db/p2p_test.go new file mode 100644 index 0000000000..9d56289b5e --- /dev/null +++ b/internal/db/p2p_test.go @@ -0,0 +1,27 @@ +// Copyright 2026 Democratized Data Foundation +// +// Use of this software is governed by the Business Source License +// included in the file licenses/BSL.txt. +// +// As of the Change Date specified in that file, in accordance with +// the Business Source License, use of this software will be governed +// by the Apache License, Version 2.0, included in the file +// licenses/APL.txt. + +package db + +import ( + "context" + "testing" + + "github.com/stretchr/testify/require" +) + +// TestDB_Connect_WithoutP2P_ReturnsError tests that an error will be returned if +// Conneect is called with P2P disabled. +func TestDB_Connect_WithoutP2P_ReturnsError(t *testing.T) { + db := &DB{} // P2P is nil + + err := db.Connect(context.Background(), []string{"/ip4/0.0.0.0/tcp/9171/p2p/12D3KooWBogusPeerID"}) + require.ErrorIs(t, err, ErrNoP2P) +} \ No newline at end of file From fc11482fc81474f5d07007f920a2690214fd4f3e Mon Sep 17 00:00:00 2001 From: Chris Quigley Date: Wed, 2 Sep 2026 16:20:07 -0400 Subject: [PATCH 2/2] Delint --- internal/db/p2p_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/db/p2p_test.go b/internal/db/p2p_test.go index 9d56289b5e..68904f361a 100644 --- a/internal/db/p2p_test.go +++ b/internal/db/p2p_test.go @@ -17,11 +17,11 @@ import ( "github.com/stretchr/testify/require" ) -// TestDB_Connect_WithoutP2P_ReturnsError tests that an error will be returned if +// TestDB_Connect_WithoutP2P_ReturnsError tests that an error will be returned if // Conneect is called with P2P disabled. func TestDB_Connect_WithoutP2P_ReturnsError(t *testing.T) { db := &DB{} // P2P is nil err := db.Connect(context.Background(), []string{"/ip4/0.0.0.0/tcp/9171/p2p/12D3KooWBogusPeerID"}) require.ErrorIs(t, err, ErrNoP2P) -} \ No newline at end of file +}