Introduce HubService struct with types for hub coordination: PendingOp, HubClaim, LeaderboardEntry, GlobalStats, ConflictError, NotFoundError. Constructor generates a crypto/rand client ID when none exists. Includes no-op loadPendingOps/savePendingOps stubs for future persistence. Co-Authored-By: Virgil <virgil@lethean.io> Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
48 lines
1.1 KiB
Go
48 lines
1.1 KiB
Go
package bugseti
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func testHubService(t *testing.T, serverURL string) *HubService {
|
|
t.Helper()
|
|
cfg := testConfigService(t, nil, nil)
|
|
if serverURL != "" {
|
|
cfg.config.HubURL = serverURL
|
|
}
|
|
return NewHubService(cfg)
|
|
}
|
|
|
|
// ---- NewHubService ----
|
|
|
|
func TestNewHubService_Good(t *testing.T) {
|
|
h := testHubService(t, "")
|
|
require.NotNil(t, h)
|
|
assert.NotNil(t, h.config)
|
|
assert.NotNil(t, h.client)
|
|
assert.False(t, h.IsConnected())
|
|
}
|
|
|
|
func TestHubServiceName_Good(t *testing.T) {
|
|
h := testHubService(t, "")
|
|
assert.Equal(t, "HubService", h.ServiceName())
|
|
}
|
|
|
|
func TestNewHubService_Good_GeneratesClientID(t *testing.T) {
|
|
h := testHubService(t, "")
|
|
id := h.GetClientID()
|
|
assert.NotEmpty(t, id)
|
|
// 16 bytes = 32 hex characters
|
|
assert.Len(t, id, 32)
|
|
}
|
|
|
|
func TestNewHubService_Good_ReusesClientID(t *testing.T) {
|
|
cfg := testConfigService(t, nil, nil)
|
|
cfg.config.ClientID = "existing-client-id"
|
|
|
|
h := NewHubService(cfg)
|
|
assert.Equal(t, "existing-client-id", h.GetClientID())
|
|
}
|