Skip to content

Commit 59ebba5

Browse files
committed
test: add NamedPidPath/NamedLogPath tests
1 parent 2a3cdb5 commit 59ebba5

2 files changed

Lines changed: 76 additions & 1 deletion

File tree

README.md

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Core library for [tunylo](https://github.com/tunylo/cli). Provides the shared pa
66

77
| Package | Description |
88
|---------|-------------|
9-
| `config` | Config loading, saving, and platform-aware paths |
9+
| `config` | Config loading, saving, and platform-aware paths (including named PID/log paths for background tunnels) |
1010
| `tunnels` | Tunnel interface, registry, and provider implementations |
1111
| `server` | Local reverse proxy with passcode access control and request logging |
1212

@@ -26,6 +26,45 @@ import (
2626
)
2727
```
2828

29+
### config
30+
31+
```go
32+
cfg, err := config.Load()
33+
34+
pidPath, err := config.NamedPidPath("myapp")
35+
logPath, err := config.NamedLogPath("myapp")
36+
```
37+
38+
Platform paths:
39+
40+
| OS | Base directory |
41+
|----|----------------|
42+
| macOS | `~/Library/Application Support/tunylo/` |
43+
| Linux / other | `~/.config/tunylo/` |
44+
45+
Named PID files are stored under `<base>/pids/<name>.pid` and log files under `<base>/logs/<name>.log`.
46+
47+
### tunnels
48+
49+
```go
50+
for _, t := range tunnels.AllTunnels() {
51+
fmt.Println(t.Key(), t.Label(), t.IsInstalled())
52+
}
53+
54+
t := tunnels.AllTunnels()[0]
55+
proc, err := t.Start("localhost", 3000)
56+
fmt.Println(*proc.PublicURL)
57+
```
58+
59+
### server
60+
61+
```go
62+
p, err := server.New("mysecret", "localhost", 3000)
63+
port, err := p.Start(ctx)
64+
```
65+
66+
Starts a local reverse proxy on a random port. Incoming requests are gated behind a passcode unlock page. Failed attempts are rate-limited per IP.
67+
2968
## License
3069

3170
MIT

config/config_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"encoding/json"
55
"os"
66
"path/filepath"
7+
"strings"
78
"testing"
89
)
910

@@ -52,3 +53,38 @@ func TestLoadInvalidJSON(t *testing.T) {
5253
t.Fatal("expected error parsing invalid JSON")
5354
}
5455
}
56+
57+
func TestNamedPidPath(t *testing.T) {
58+
t.Setenv("HOME", t.TempDir())
59+
60+
path, err := NamedPidPath("myapp")
61+
if err != nil {
62+
t.Fatalf("NamedPidPath returned error: %v", err)
63+
}
64+
if !strings.HasSuffix(path, filepath.Join("pids", "myapp.pid")) {
65+
t.Fatalf("unexpected pid path: %s", path)
66+
}
67+
}
68+
69+
func TestNamedLogPath(t *testing.T) {
70+
t.Setenv("HOME", t.TempDir())
71+
72+
path, err := NamedLogPath("myapp")
73+
if err != nil {
74+
t.Fatalf("NamedLogPath returned error: %v", err)
75+
}
76+
if !strings.HasSuffix(path, filepath.Join("logs", "myapp.log")) {
77+
t.Fatalf("unexpected log path: %s", path)
78+
}
79+
}
80+
81+
func TestNamedPathsAreDifferentPerName(t *testing.T) {
82+
t.Setenv("HOME", t.TempDir())
83+
84+
a, _ := NamedPidPath("alpha")
85+
b, _ := NamedPidPath("beta")
86+
if a == b {
87+
t.Fatal("different names should produce different pid paths")
88+
}
89+
}
90+

0 commit comments

Comments
 (0)