| 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "os" |
| 5 | "path/filepath" |
| 6 | "testing" |
| 7 | |
| 8 | "github.com/sylvinus/agent-vm/internal/mobilelink" |
| 9 | ) |
| 10 | |
| 11 | func TestNewPairingUsesDesktopRelay(t *testing.T) { |
| 12 | dir := t.TempDir() |
| 13 | config := filepath.Join(dir, "config.json") |
| 14 | prefs := filepath.Join(dir, "workbench.json") |
| 15 | for _, tc := range []struct{ name, json, want string }{ |
| 16 | {"new profile", "", mobilelink.OfficialRelay}, |
| 17 | {"existing profile", `{"keyboard":"mac"}`, mobilelink.OfficialRelay}, |
| 18 | {"custom relay", `{"mobile_relay":"https://relay.example:8443"}`, "https://relay.example:8443"}, |
| 19 | {"damaged preferences", "{", ""}, |
| 20 | {"insecure relay", `{"mobile_relay":"http://relay.example"}`, ""}, |
| 21 | } { |
| 22 | t.Run(tc.name, func(t *testing.T) { |
| 23 | if tc.json != "" { |
| 24 | if err := os.WriteFile(prefs, []byte(tc.json), 0600); err != nil { |
| 25 | t.Fatal(err) |
| 26 | } |
| 27 | } |
| 28 | origin, err := profileRelay(config) |
| 29 | if origin != tc.want || (err != nil) != (tc.want == "") { |
| 30 | t.Fatalf("origin = %q, error = %v", origin, err) |
| 31 | } |
| 32 | }) |
| 33 | } |
| 34 | } |