(t *testing.T)
| 167 | } |
| 168 | |
| 169 | func TestServerControlUDS(t *testing.T) { |
| 170 | if runtime.GOOS == "windows" { |
| 171 | t.Skip() |
| 172 | } |
| 173 | |
| 174 | env := testenv.NewCLITest(t, testenv.RepoFormatNotImportant, testenv.NewInProcRunner(t)) |
| 175 | |
| 176 | dir0 := testutil.TempDirectory(t) |
| 177 | // the socket path must be < 108 bytes (linux) or 104 bytes (Mac), so can't use long tempdir |
| 178 | dir1 := testutil.TempDirectoryShort(t) |
| 179 | |
| 180 | env.RunAndExpectSuccess(t, "repo", "create", "filesystem", "--path", env.RepoDir, "--override-username=another-user", "--override-hostname=another-host") |
| 181 | env.RunAndExpectSuccess(t, "snap", "create", dir0) |
| 182 | |
| 183 | env.RunAndExpectSuccess(t, "repo", "connect", "filesystem", "--path", env.RepoDir, "--override-username=test-user", "--override-hostname=test-host") |
| 184 | |
| 185 | serverStarted := make(chan struct{}) |
| 186 | serverStopped := make(chan struct{}) |
| 187 | |
| 188 | var sp testutil.ServerParameters |
| 189 | |
| 190 | go func() { |
| 191 | wait, _ := env.RunAndProcessStderr(t, sp.ProcessOutput, |
| 192 | "server", "start", "--insecure", "--random-server-control-password", "--address="+"unix:"+dir1+"/sock") |
| 193 | |
| 194 | close(serverStarted) |
| 195 | |
| 196 | wait() |
| 197 | |
| 198 | close(serverStopped) |
| 199 | }() |
| 200 | |
| 201 | select { |
| 202 | case <-serverStarted: |
| 203 | t.Logf("server started on %v", sp.BaseURL) |
| 204 | |
| 205 | case <-time.After(5 * time.Second): |
| 206 | t.Fatalf("server did not start in time") |
| 207 | } |
| 208 | |
| 209 | lines := env.RunAndExpectSuccess(t, "server", "status", "--address", sp.BaseURL, "--server-control-password", sp.ServerControlPassword, "--remote") |
| 210 | require.Len(t, lines, 1) |
| 211 | require.Contains(t, lines, "REMOTE: another-user@another-host:"+dir0) |
| 212 | |
| 213 | env.RunAndExpectSuccess(t, "server", "shutdown", "--address", sp.BaseURL, "--server-control-password", sp.ServerControlPassword) |
| 214 | |
| 215 | select { |
| 216 | case <-serverStopped: |
| 217 | t.Logf("server shut down") |
| 218 | |
| 219 | case <-time.After(15 * time.Second): |
| 220 | t.Fatalf("server did not shutdown in time") |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | func hasLine(lines []string, lookFor string) bool { |
| 225 | return slices.Contains(lines, lookFor) |
nothing calls this directly
no test coverage detected