network/pkg/client/defaults_test.go
anonpenguin23 69d7ccf4c7 feat: enhance IPFS and Cluster integration in setup
- Added automatic setup for IPFS and IPFS Cluster during the network setup process.
- Implemented initialization of IPFS repositories and Cluster configurations for each node.
- Enhanced Makefile to support starting IPFS and Cluster daemons with improved logging.
- Introduced a new documentation guide for IPFS Cluster setup, detailing configuration and verification steps.
- Updated changelog to reflect the new features and improvements.
2025-11-05 10:52:40 +02:00

58 lines
1.6 KiB
Go

package client
import (
"os"
"testing"
"github.com/multiformats/go-multiaddr"
)
func TestDefaultBootstrapPeersNonEmpty(t *testing.T) {
old := os.Getenv("DEBROS_BOOTSTRAP_PEERS")
t.Cleanup(func() { os.Setenv("DEBROS_BOOTSTRAP_PEERS", old) })
// Set a valid bootstrap peer
validPeer := "/ip4/localhost/tcp/4001/p2p/12D3KooWHbcFcrGPXKUrHcxvd8MXEeUzRYyvY8fQcpEBxncSUwhj"
_ = os.Setenv("DEBROS_BOOTSTRAP_PEERS", validPeer)
peers := DefaultBootstrapPeers()
if len(peers) == 0 {
t.Fatalf("expected non-empty default bootstrap peers")
}
if peers[0] != validPeer {
t.Fatalf("expected bootstrap peer %s, got %s", validPeer, peers[0])
}
}
func TestDefaultDatabaseEndpointsEnvOverride(t *testing.T) {
oldNodes := os.Getenv("RQLITE_NODES")
t.Cleanup(func() { os.Setenv("RQLITE_NODES", oldNodes) })
_ = os.Setenv("RQLITE_NODES", "db1.local:7001, https://db2.local:7443")
endpoints := DefaultDatabaseEndpoints()
if len(endpoints) != 2 {
t.Fatalf("expected 2 endpoints from env, got %v", endpoints)
}
}
func TestNormalizeEndpoints(t *testing.T) {
in := []string{"db.local", "http://db.local:5001", "[::1]", "https://host:8443"}
out := normalizeEndpoints(in)
if len(out) != 4 {
t.Fatalf("unexpected len: %v", out)
}
foundDefault := false
for _, s := range out {
if s == "http://db.local:5001" {
foundDefault = true
}
}
if !foundDefault {
t.Fatalf("missing normalized default port: %v", out)
}
}
func TestEndpointFromMultiaddr(t *testing.T) {
ma, _ := multiaddr.NewMultiaddr("/ip4/localhost/tcp/4001")
if ep := endpointFromMultiaddr(ma, 5001); ep != "http://localhost:5001" {
t.Fatalf("unexpected endpoint: %s", ep)
}
}