mirror of
https://github.com/netbirdio/netbird.git
synced 2026-10-23 05:49:07 +02:00
Aligns tests
This commit is contained in:
@@ -15,10 +15,15 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func newTestServer() *Server {
|
func newTestServer() *Server {
|
||||||
return &Server{
|
ctx := context.Background()
|
||||||
rootCtx: context.Background(),
|
s := &Server{
|
||||||
|
rootCtx: ctx,
|
||||||
statusRecorder: peer.NewRecorder(""),
|
statusRecorder: peer.NewRecorder(""),
|
||||||
}
|
}
|
||||||
|
// Honor the production invariant: the daemon-lifetime client always exists
|
||||||
|
// (built in New). Server methods rely on s.connectClient being non-nil.
|
||||||
|
s.connectClient = internal.NewConnectClient(ctx, s.statusRecorder)
|
||||||
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
func newDummyConnectClient(ctx context.Context) *internal.ConnectClient {
|
func newDummyConnectClient(ctx context.Context) *internal.ConnectClient {
|
||||||
@@ -95,35 +100,28 @@ func TestCleanupConnection_KeepsClientStopsRunning(t *testing.T) {
|
|||||||
_, cancel := context.WithCancel(context.Background())
|
_, cancel := context.WithCancel(context.Background())
|
||||||
s.actCancel = cancel
|
s.actCancel = cancel
|
||||||
|
|
||||||
s.connectClient = newDummyConnectClient(context.Background())
|
|
||||||
s.clientRunning = true
|
|
||||||
|
|
||||||
err := s.cleanupConnection()
|
err := s.cleanupConnection()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
assert.NotNil(t, s.connectClient, "connectClient is daemon-lifetime and must persist after cleanup")
|
assert.NotNil(t, s.connectClient, "connectClient is daemon-lifetime and must persist after cleanup")
|
||||||
assert.False(t, s.connectClient.IsRunning(), "no run should be in flight after cleanup")
|
assert.False(t, s.connectClient.ConnectionRunning(), "no run should be in flight after cleanup")
|
||||||
assert.False(t, s.clientRunning, "clientRunning should be cleared after cleanup (intent = down)")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestCleanState_NilConnectClient validates that CleanState doesn't panic
|
// TestCleanState_NotConnected validates that CleanState doesn't panic when no
|
||||||
// when connectClient is nil.
|
// connection run is in flight.
|
||||||
func TestCleanState_NilConnectClient(t *testing.T) {
|
func TestCleanState_NotConnected(t *testing.T) {
|
||||||
s := newTestServer()
|
s := newTestServer()
|
||||||
s.connectClient = nil
|
s.profileManager = nil // will cause error if it tries to proceed
|
||||||
s.profileManager = nil // will cause error if it tries to proceed past the nil check
|
|
||||||
|
|
||||||
// Should not panic — the nil check should prevent calling Status() on nil
|
|
||||||
assert.NotPanics(t, func() {
|
assert.NotPanics(t, func() {
|
||||||
_, _ = s.CleanState(context.Background(), &proto.CleanStateRequest{All: true})
|
_, _ = s.CleanState(context.Background(), &proto.CleanStateRequest{All: true})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestDeleteState_NilConnectClient validates that DeleteState doesn't panic
|
// TestDeleteState_NotConnected validates that DeleteState doesn't panic when no
|
||||||
// when connectClient is nil.
|
// connection run is in flight.
|
||||||
func TestDeleteState_NilConnectClient(t *testing.T) {
|
func TestDeleteState_NotConnected(t *testing.T) {
|
||||||
s := newTestServer()
|
s := newTestServer()
|
||||||
s.connectClient = nil
|
|
||||||
s.profileManager = nil
|
s.profileManager = nil
|
||||||
|
|
||||||
assert.NotPanics(t, func() {
|
assert.NotPanics(t, func() {
|
||||||
|
|||||||
Reference in New Issue
Block a user