Something went wrong. Try again.
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788package tailnet
import ( "context" "errors" "strconv" "testing"
"100gex/internal/rex/rextest")
const fixture = `{ "Self": {"HostName": "sidon", "DNSName": "sidon.tail1234.ts.net.", "OS": "linux", "Online": false, "TailscaleIPs": ["100.64.0.1"]}, "Peer": { "a": {"HostName": "studio", "DNSName": "studio.tail1234.ts.net.", "OS": "macOS", "Online": true, "sshHostKeys": ["ssh-ed25519 AAAA"]}, "b": {"HostName": "attic", "DNSName": "attic.tail1234.ts.net.", "OS": "linux", "Online": false}, "c": {"HostName": "us-lax-wg-402", "DNSName": "us-lax-wg-402.mullvad.ts.net.", "OS": "", "Online": true, "Location": {"Country": "USA"}}, "d": {"HostName": "Daniels-iPhone", "DNSName": "iphone.tail1234.ts.net.", "OS": "iOS", "Online": true}, "e": {"HostName": "nodns", "DNSName": "", "OS": "linux", "Online": true, "TailscaleIPs": ["fd7a::1", "100.64.0.9"]}, "f": {"HostName": "Bravo", "DNSName": "bravo.tail1234.ts.net.", "OS": "windows", "Online": true, "Location": null} }}`
func TestParse(t *testing.T) { got, err := Parse([]byte(fixture)) if err != nil { t.Fatal(err) } var names []string for _, m := range got { names = append(names, m.Name+"="+m.Address) } want := []string{ "sidon=sidon.tail1234.ts.net", // this machine first "attic=attic.tail1234.ts.net", "bravo=bravo.tail1234.ts.net", "nodns=100.64.0.9", // no MagicDNS: its IPv4 address "studio=studio.tail1234.ts.net", } if len(names) != len(want) { t.Fatalf("machines %v, want %v (no exit node, no iPhone)", names, want) } for i := range want { if names[i] != want[i] { t.Errorf("machine %d = %s, want %s", i, names[i], want[i]) } } if !got[0].ThisMachine || !got[0].Online { t.Errorf("this machine = %+v, want online and marked", got[0]) } if s := got[4]; !s.SSH || !s.Online || s.OS != "macOS" { t.Errorf("studio = %+v", s) } if a := got[1]; a.Online { t.Errorf("attic = %+v, want offline", a) }}
func TestProbe(t *testing.T) { port := rextest.FreePort(t) rextest.StartArgs(t, "", "--extra-listen", "http://127.0.0.1:"+strconv.Itoa(port), "--allow-anonymous") ep, err := Probe(context.Background(), "127.0.0.1:"+strconv.Itoa(port)) if err != nil { t.Fatal(err) } if ep.Port != port || ep.TLS { t.Errorf("found %v, want plain HTTP on %d", ep, port) } if _, err := Probe(context.Background(), "127.0.0.1:"+strconv.Itoa(rextest.FreePort(t))); !errors.Is(err, ErrNoRex) { t.Errorf("probing nothing: %v, want ErrNoRex", err) }}
// TestMachines reads this machine's real tailnet, when there is one.func TestMachines(t *testing.T) { ms, err := Machines(context.Background()) if errors.Is(err, ErrNoTailscale) { t.Skip(err) } if err != nil { t.Fatal(err) } if len(ms) == 0 || !ms[0].ThisMachine { t.Fatalf("machines %+v, want this machine first", ms) } t.Logf("%d machines, this one %s", len(ms), ms[0].Name)}