omarchy-send/internal/server/server_test.go
28allday 2dd81700c0 Initial commit: Omarchy-Send v0.1.0
LocalSend-compatible file-transfer TUI for headless Arch/Omarchy servers.

- Pure-stdlib implementation of the LocalSend v2 protocol (discovery,
  HTTPS with matching cert fingerprint, send/receive, PIN).
- Bubble Tea TUI: Devices, Transfers, Manage (received-file housekeeping)
  and Settings, theme-aware on Omarchy.
- Dual-mode install.sh: curl-pipe download or build-from-clone.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-27 19:26:08 +01:00

52 lines
1.2 KiB
Go

package server
import (
"context"
"encoding/json"
"net/http"
"testing"
"time"
"omarchy-send/internal/protocol"
)
func TestInfoEndpoint(t *testing.T) {
info := protocol.DeviceInfo{
Alias: "test-host",
Version: protocol.ProtocolVersion,
DeviceType: protocol.DeviceServer,
Fingerprint: "deadbeef",
Port: 53999, // off the default to avoid clashing with a running instance
Protocol: "http",
}
s := New(Options{Info: info})
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
if err := s.Start(ctx); err != nil {
t.Fatalf("start: %v", err)
}
// Give Serve a beat to accept connections.
time.Sleep(50 * time.Millisecond)
resp, err := http.Get("http://127.0.0.1:53999" + protocol.PathInfo)
if err != nil {
t.Fatalf("get: %v", err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
t.Fatalf("status = %d, want 200", resp.StatusCode)
}
var got protocol.DeviceInfo
if err := json.NewDecoder(resp.Body).Decode(&got); err != nil {
t.Fatalf("decode: %v", err)
}
if got.Alias != "test-host" || got.Version != "2.1" || got.Fingerprint != "deadbeef" {
t.Fatalf("unexpected info: %+v", got)
}
if got.Protocol != "http" {
t.Fatalf("protocol = %q, want http", got.Protocol)
}
}