(t *testing.T)
| 127 | } |
| 128 | |
| 129 | func TestGatewayRunningPID(t *testing.T) { |
| 130 | tmp := t.TempDir() |
| 131 | t.Setenv("HOME", tmp) |
| 132 | _ = os.MkdirAll(filepath.Join(tmp, ".chatcli"), 0o750) |
| 133 | |
| 134 | // No pidfile yet. |
| 135 | if _, ok := gatewayRunningPID(); ok { |
| 136 | t.Error("no pidfile -> not running") |
| 137 | } |
| 138 | // Stale pidfile (dead pid) is cleared and reported as not running. |
| 139 | pidPath := gatewayStatePath("gateway.pid") |
| 140 | if err := os.WriteFile(pidPath, []byte(strconv.Itoa(1<<30)), 0o600); err != nil { |
| 141 | t.Fatal(err) |
| 142 | } |
| 143 | if _, ok := gatewayRunningPID(); ok { |
| 144 | t.Error("dead pid -> not running") |
| 145 | } |
| 146 | if _, err := os.Stat(pidPath); !os.IsNotExist(err) { |
| 147 | t.Error("stale pidfile should be removed") |
| 148 | } |
| 149 | // Live pid (ourselves) is reported running. |
| 150 | if err := os.WriteFile(pidPath, []byte(strconv.Itoa(os.Getpid())), 0o600); err != nil { |
| 151 | t.Fatal(err) |
| 152 | } |
| 153 | if pid, ok := gatewayRunningPID(); !ok || pid != os.Getpid() { |
| 154 | t.Errorf("live pid should be running, got pid=%d ok=%v", pid, ok) |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | // TestGatewayCommands_NoPanic exercises the status/stop/start branches with no |
| 159 | // platforms configured and no daemon running (temp HOME), covering the command |
nothing calls this directly
no test coverage detected