fix: correction de toutes les erreurs CI — vet, lint, race detector et config
CI / Lint (push) Successful in 18m7s
CI / Test (push) Successful in 9m2s
CI / Build (darwin/amd64) (push) Failing after 4m4s
CI / Build (linux/amd64) (push) Failing after 4m7s
CI / Build (windows/amd64) (push) Failing after 4m5s
CI / Build (darwin/arm64) (push) Failing after 4m4s
CI / Build (linux/arm64) (push) Failing after 4m7s
CI / Build (windows/arm64) (push) Failing after 4m6s
CI / Release (push) Skipped
CI / Lint (push) Successful in 18m7s
CI / Test (push) Successful in 9m2s
CI / Build (darwin/amd64) (push) Failing after 4m4s
CI / Build (linux/amd64) (push) Failing after 4m7s
CI / Build (windows/amd64) (push) Failing after 4m5s
CI / Build (darwin/arm64) (push) Failing after 4m4s
CI / Build (linux/arm64) (push) Failing after 4m7s
CI / Build (windows/arm64) (push) Failing after 4m6s
CI / Release (push) Skipped
- clipboard_windows.go: remplacement unsafe.Pointer par unsafe.Add pour go vet 1.26 - clipboard_windows.go: correction errcheck (defer syscall) et ineffassign - daemon_test.go: mockClipboard thread-safe avec sync.RWMutex (data race) - daemon_test.go: correction errcheck sur go da.Run() - server_test.go: vérification des erreurs json.Marshal - config_test.go: vérification des erreurs MkdirAll/WriteFile - peers.example.toml: mise à jour au format TOML actuel
This commit is contained in:
@@ -2,6 +2,7 @@ package daemon
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -10,11 +11,34 @@ import (
|
||||
|
||||
// mockClipboard is a thread-safe in-memory clipboard for integration tests.
|
||||
type mockClipboard struct {
|
||||
mu sync.RWMutex
|
||||
text string
|
||||
}
|
||||
|
||||
func (m *mockClipboard) Read() (string, error) { return m.text, nil }
|
||||
func (m *mockClipboard) Write(s string) error { m.text = s; return nil }
|
||||
func (m *mockClipboard) Read() (string, error) {
|
||||
m.mu.RLock()
|
||||
defer m.mu.RUnlock()
|
||||
return m.text, nil
|
||||
}
|
||||
|
||||
func (m *mockClipboard) Write(s string) error {
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
m.text = s
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *mockClipboard) get() string {
|
||||
m.mu.RLock()
|
||||
defer m.mu.RUnlock()
|
||||
return m.text
|
||||
}
|
||||
|
||||
func (m *mockClipboard) set(s string) {
|
||||
m.mu.Lock()
|
||||
defer m.mu.Unlock()
|
||||
m.text = s
|
||||
}
|
||||
|
||||
// TestIntegrationTwoInstances simulates two clip-sync instances syncing via localhost
|
||||
// with distinct origins to avoid the same-hostname anti-loop filter.
|
||||
@@ -53,33 +77,33 @@ func TestIntegrationTwoInstances(t *testing.T) {
|
||||
}
|
||||
|
||||
// Start both daemons.
|
||||
go da.Run(ctx)
|
||||
go db.Run(ctx)
|
||||
go func() { _ = da.Run(ctx) }()
|
||||
go func() { _ = db.Run(ctx) }()
|
||||
|
||||
// Wait for servers to start.
|
||||
time.Sleep(200 * time.Millisecond)
|
||||
|
||||
// Write text to mock clipboard A (simulating a local copy).
|
||||
cbA.text = "sync test from A"
|
||||
da.filter.MarkWritten(cbA.text)
|
||||
da.broadcaster.Broadcast(cbA.text)
|
||||
cbA.set("sync test from A")
|
||||
da.filter.MarkWritten(cbA.get())
|
||||
da.broadcaster.Broadcast(cbA.get())
|
||||
|
||||
// Wait for propagation A → B via HTTP.
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
|
||||
if cbB.text != "sync test from A" {
|
||||
t.Errorf("B clipboard = %q, want \"sync test from A\"", cbB.text)
|
||||
if got := cbB.get(); got != "sync test from A" {
|
||||
t.Errorf("B clipboard = %q, want \"sync test from A\"", got)
|
||||
}
|
||||
|
||||
// Now write to B and check A.
|
||||
cbB.text = "sync test from B"
|
||||
db.filter.MarkWritten(cbB.text)
|
||||
db.broadcaster.Broadcast(cbB.text)
|
||||
cbB.set("sync test from B")
|
||||
db.filter.MarkWritten(cbB.get())
|
||||
db.broadcaster.Broadcast(cbB.get())
|
||||
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
|
||||
if cbA.text != "sync test from B" {
|
||||
t.Errorf("A clipboard = %q, want \"sync test from B\"", cbA.text)
|
||||
if got := cbA.get(); got != "sync test from B" {
|
||||
t.Errorf("A clipboard = %q, want \"sync test from B\"", got)
|
||||
}
|
||||
|
||||
cancel()
|
||||
@@ -117,19 +141,19 @@ func TestNoPingPong(t *testing.T) {
|
||||
t.Fatalf("daemon B: %v", err)
|
||||
}
|
||||
|
||||
go da.Run(ctx)
|
||||
go db.Run(ctx)
|
||||
go func() { _ = da.Run(ctx) }()
|
||||
go func() { _ = db.Run(ctx) }()
|
||||
time.Sleep(200 * time.Millisecond)
|
||||
|
||||
// Phase 1: Write to A, verify B receives it.
|
||||
cbA.text = "ping-pong test"
|
||||
da.filter.MarkWritten(cbA.text)
|
||||
da.broadcaster.Broadcast(cbA.text)
|
||||
cbA.set("ping-pong test")
|
||||
da.filter.MarkWritten(cbA.get())
|
||||
da.broadcaster.Broadcast(cbA.get())
|
||||
|
||||
time.Sleep(400 * time.Millisecond)
|
||||
|
||||
if cbB.text != "ping-pong test" {
|
||||
t.Errorf("B clipboard = %q, want \"ping-pong test\"", cbB.text)
|
||||
if got := cbB.get(); got != "ping-pong test" {
|
||||
t.Errorf("B clipboard = %q, want \"ping-pong test\"", got)
|
||||
}
|
||||
|
||||
// Phase 2: B's poller detects the new text and broadcasts it back.
|
||||
@@ -139,14 +163,14 @@ func TestNoPingPong(t *testing.T) {
|
||||
|
||||
// Phase 3: Write new text on B, verify A receives it correctly
|
||||
// (no interference from the blocked echo).
|
||||
cbB.text = "final test"
|
||||
db.filter.MarkWritten(cbB.text)
|
||||
db.broadcaster.Broadcast(cbB.text)
|
||||
cbB.set("final test")
|
||||
db.filter.MarkWritten(cbB.get())
|
||||
db.broadcaster.Broadcast(cbB.get())
|
||||
|
||||
time.Sleep(400 * time.Millisecond)
|
||||
|
||||
if cbA.text != "final test" {
|
||||
t.Errorf("A clipboard = %q, want \"final test\"", cbA.text)
|
||||
if got := cbA.get(); got != "final test" {
|
||||
t.Errorf("A clipboard = %q, want \"final test\"", got)
|
||||
}
|
||||
|
||||
cancel()
|
||||
|
||||
Reference in New Issue
Block a user