diff --git a/testscript/script_test.go b/testscript/script_test.go index 43fdde900..564372808 100644 --- a/testscript/script_test.go +++ b/testscript/script_test.go @@ -79,20 +79,20 @@ func TestScript(t *testing.T) { UpdateScripts: *update, RequireExplicitExec: true, Cmds: map[string]func(ts *testscript.TestScript, neg bool, args []string){ - "soft": cmdSoft("admin", admin1.Signer()), - "usoft": cmdSoft("user1", user1.Signer()), - "git": cmdGit(admin1Key), - "ugit": cmdGit(user1Key), - "curl": cmdCurl, - "mkfile": cmdMkfile, - "envfile": cmdEnvfile, - "readfile": cmdReadfile, - "dos2unix": cmdDos2Unix, - "new-webhook": cmdNewWebhook, - "waitforserver": cmdWaitforserver, - "stopserver": cmdStopserver, - "ui": cmdUI(admin1.Signer()), - "uui": cmdUI(user1.Signer()), + "soft": cmdSoft("admin", admin1.Signer()), + "usoft": cmdSoft("user1", user1.Signer()), + "git": cmdGit(admin1Key), + "ugit": cmdGit(user1Key), + "curl": cmdCurl, + "mkfile": cmdMkfile, + "envfile": cmdEnvfile, + "readfile": cmdReadfile, + "dos2unix": cmdDos2Unix, + "new-webhook": cmdNewWebhook, + "ensureserverrunning": cmdEnsureServerRunning, + "stopserver": cmdStopserver, + "ui": cmdUI(admin1.Signer()), + "uui": cmdUI(user1.Signer()), }, Setup: func(e *testscript.Env) error { // Add binPath to PATH @@ -470,9 +470,18 @@ func cmdCurl(ts *testscript.TestScript, neg bool, args []string) { check(ts, cmd.Execute(), neg) } -func cmdWaitforserver(ts *testscript.TestScript, neg bool, args []string) { - // wait until the server is up - addr := net.JoinHostPort("localhost", ts.Getenv("SSH_PORT")) +func cmdEnsureServerRunning(ts *testscript.TestScript, neg bool, args []string) { + if len(args) < 1 { + ts.Fatalf("Must supply a TCP port of one of the services to connect to. " + + "These are set as env vars as they are randomized. " + + "Example usage: \"cmdensureserverrunning SSH_PORT\"\n" + + "Valid values for the env var: SSH_PORT|HTTP_PORT|GIT_PORT|STATS_PORT") + } + + port := ts.Getenv(args[0]) + + // verify that the server is up + addr := net.JoinHostPort("localhost", port) for { conn, _ := net.DialTimeout( "tcp", @@ -480,6 +489,7 @@ func cmdWaitforserver(ts *testscript.TestScript, neg bool, args []string) { time.Second, ) if conn != nil { + ts.Logf("Server is running on port: %s", port) conn.Close() break } diff --git a/testscript/testdata/anon-access.txtar b/testscript/testdata/anon-access.txtar index 54958fa11..c43dc23cd 100644 --- a/testscript/testdata/anon-access.txtar +++ b/testscript/testdata/anon-access.txtar @@ -2,8 +2,8 @@ # start soft serve exec soft serve & -# wait for server to start -waitforserver +# wait for SSH server to start +ensureserverrunning SSH_PORT # set settings soft settings allow-keyless true diff --git a/testscript/testdata/help.txtar b/testscript/testdata/help.txtar index d6756ca02..299e29500 100644 --- a/testscript/testdata/help.txtar +++ b/testscript/testdata/help.txtar @@ -3,8 +3,8 @@ # start soft serve exec soft serve --sync-hooks & -# wait for server to start -waitforserver +# wait for SSH server to start +ensureserverrunning SSH_PORT soft --help cmpenv stdout help.txt diff --git a/testscript/testdata/http.txtar b/testscript/testdata/http.txtar index 98f6902a5..796c6421a 100644 --- a/testscript/testdata/http.txtar +++ b/testscript/testdata/http.txtar @@ -8,8 +8,8 @@ # start soft serve exec soft serve & -# wait for server to start -waitforserver +# wait for SSH server to start +ensureserverrunning SSH_PORT # create user soft user create user1 --key "$USER1_AUTHORIZED_KEY" diff --git a/testscript/testdata/jwt.txtar b/testscript/testdata/jwt.txtar index 7a257044e..667ec7985 100644 --- a/testscript/testdata/jwt.txtar +++ b/testscript/testdata/jwt.txtar @@ -2,8 +2,8 @@ # start soft serve exec soft serve & -# wait for server to start -waitforserver +# wait for SSH server to start +ensureserverrunning SSH_PORT # create user soft user create user1 --key "$USER1_AUTHORIZED_KEY" diff --git a/testscript/testdata/mirror.txtar b/testscript/testdata/mirror.txtar index d3cc1915d..76feb782e 100644 --- a/testscript/testdata/mirror.txtar +++ b/testscript/testdata/mirror.txtar @@ -5,8 +5,8 @@ # start soft serve exec soft serve & -# wait for server to start -waitforserver +# wait for SSH server to start +ensureserverrunning SSH_PORT # import a repo soft repo import --mirror charmbracelet/catwalk https://github.com/charmbracelet/catwalk.git diff --git a/testscript/testdata/repo-blob.txtar b/testscript/testdata/repo-blob.txtar index e2712acfe..685c15d80 100644 --- a/testscript/testdata/repo-blob.txtar +++ b/testscript/testdata/repo-blob.txtar @@ -5,8 +5,8 @@ # start soft serve exec soft serve & -# wait for server to start -waitforserver +# wait for SSH server to start +ensureserverrunning SSH_PORT # create a repo soft repo create repo1 diff --git a/testscript/testdata/repo-collab.txtar b/testscript/testdata/repo-collab.txtar index d2960693a..ead5fdce4 100644 --- a/testscript/testdata/repo-collab.txtar +++ b/testscript/testdata/repo-collab.txtar @@ -2,8 +2,8 @@ # start soft serve exec soft serve & -# wait for server to start -waitforserver +# wait for SSH server to start +ensureserverrunning SSH_PORT # setup soft repo import test https://github.com/charmbracelet/catwalk.git diff --git a/testscript/testdata/repo-commit.txtar b/testscript/testdata/repo-commit.txtar index 70ca3da12..a3b61e514 100644 --- a/testscript/testdata/repo-commit.txtar +++ b/testscript/testdata/repo-commit.txtar @@ -5,8 +5,8 @@ # start soft serve exec soft serve & -# wait for server to start -waitforserver +# wait for SSH server to start +ensureserverrunning SSH_PORT # create a repo soft repo import basic1 https://github.com/git-fixtures/basic diff --git a/testscript/testdata/repo-create.txtar b/testscript/testdata/repo-create.txtar index 7b7f12d77..2b8cf4522 100644 --- a/testscript/testdata/repo-create.txtar +++ b/testscript/testdata/repo-create.txtar @@ -5,8 +5,8 @@ # start soft serve exec soft serve & -# wait for server to start -waitforserver +# wait for SSH server to start +ensureserverrunning SSH_PORT # create a repo soft repo create repo1 -d 'description' -H -p -n 'repo11' diff --git a/testscript/testdata/repo-delete.txtar b/testscript/testdata/repo-delete.txtar index ca513e782..b9197e17d 100644 --- a/testscript/testdata/repo-delete.txtar +++ b/testscript/testdata/repo-delete.txtar @@ -2,8 +2,8 @@ # start soft serve exec soft serve & -# wait for server to start -waitforserver +# wait for SSH server to start +ensureserverrunning SSH_PORT soft repo create repo1 soft repo create repo-to-delete diff --git a/testscript/testdata/repo-import.txtar b/testscript/testdata/repo-import.txtar index 84d4334b4..e9bfa31e4 100644 --- a/testscript/testdata/repo-import.txtar +++ b/testscript/testdata/repo-import.txtar @@ -5,8 +5,8 @@ # start soft serve exec soft serve & -# wait for server to start -waitforserver +# wait for SSH server to start +ensureserverrunning SSH_PORT # import private soft repo import --private repo1 https://github.com/charmbracelet/catwalk.git diff --git a/testscript/testdata/repo-perms.txtar b/testscript/testdata/repo-perms.txtar index 1cc371e93..a3e4515c0 100644 --- a/testscript/testdata/repo-perms.txtar +++ b/testscript/testdata/repo-perms.txtar @@ -5,8 +5,8 @@ # start soft serve exec soft serve & -# wait for server to start -waitforserver +# wait for SSH server to start +ensureserverrunning SSH_PORT # create a repo & user1 with admin soft repo create repo1 -p diff --git a/testscript/testdata/repo-push.txtar b/testscript/testdata/repo-push.txtar index cadb735b9..d9f947537 100644 --- a/testscript/testdata/repo-push.txtar +++ b/testscript/testdata/repo-push.txtar @@ -2,8 +2,8 @@ # start soft serve exec soft serve & -# wait for server to start -waitforserver +# wait for SSH server to start +ensureserverrunning SSH_PORT # create a repo soft repo create repo-empty -d 'description' -H -p -n 'repo-empty' diff --git a/testscript/testdata/repo-tree.txtar b/testscript/testdata/repo-tree.txtar index b3e6320de..75a9978a2 100644 --- a/testscript/testdata/repo-tree.txtar +++ b/testscript/testdata/repo-tree.txtar @@ -5,8 +5,8 @@ # start soft serve exec soft serve & -# wait for server to start -waitforserver +# wait for SSH server to start +ensureserverrunning SSH_PORT # create a repo soft repo create repo1 diff --git a/testscript/testdata/repo-webhooks.txtar b/testscript/testdata/repo-webhooks.txtar index fe393a5b6..6b370d31e 100644 --- a/testscript/testdata/repo-webhooks.txtar +++ b/testscript/testdata/repo-webhooks.txtar @@ -2,8 +2,8 @@ # start soft serve exec soft serve & -# wait for server to start -waitforserver +# wait for SSH server to start +ensureserverrunning SSH_PORT # create a repo soft repo create repo-123 diff --git a/testscript/testdata/set-username.txtar b/testscript/testdata/set-username.txtar index 30f1a8e00..745134c73 100644 --- a/testscript/testdata/set-username.txtar +++ b/testscript/testdata/set-username.txtar @@ -5,8 +5,8 @@ # start soft serve exec soft serve & -# wait for server to start -waitforserver +# wait for SSH server to start +ensureserverrunning SSH_PORT # get original username soft info diff --git a/testscript/testdata/settings.txtar b/testscript/testdata/settings.txtar index 1ceaec57d..fc6bdf463 100644 --- a/testscript/testdata/settings.txtar +++ b/testscript/testdata/settings.txtar @@ -2,8 +2,8 @@ # start soft serve exec soft serve & -# wait for server to start -waitforserver +# wait for SSH server to start +ensureserverrunning SSH_PORT # check default allow-keyless soft settings allow-keyless true diff --git a/testscript/testdata/ssh-lfs.txtar b/testscript/testdata/ssh-lfs.txtar index fbba49d3e..a647dff91 100644 --- a/testscript/testdata/ssh-lfs.txtar +++ b/testscript/testdata/ssh-lfs.txtar @@ -8,8 +8,8 @@ skip 'breaks with git-lfs 3.5.1' env SOFT_SERVE_LFS_SSH_ENABLED=true # start soft serve exec soft serve & -# wait for server to start -waitforserver +# wait for SSH server to start +ensureserverrunning SSH_PORT # create a user soft user create foo --key "$USER1_AUTHORIZED_KEY" diff --git a/testscript/testdata/ssh.txtar b/testscript/testdata/ssh.txtar index 3e652aeb2..e968fa63a 100644 --- a/testscript/testdata/ssh.txtar +++ b/testscript/testdata/ssh.txtar @@ -4,8 +4,8 @@ # start soft serve exec soft serve & -# wait for server to start -waitforserver +# wait for SSH server to start +ensureserverrunning SSH_PORT # create a user soft user create foo --key "$USER1_AUTHORIZED_KEY" diff --git a/testscript/testdata/token.txtar b/testscript/testdata/token.txtar index 821cea84d..7a88701c1 100644 --- a/testscript/testdata/token.txtar +++ b/testscript/testdata/token.txtar @@ -2,8 +2,8 @@ # start soft serve exec soft serve & -# wait for server to start -waitforserver +# wait for SSH server to start +ensureserverrunning SSH_PORT # create user soft user create user1 --key "$USER1_AUTHORIZED_KEY" diff --git a/testscript/testdata/ui-home.txtar b/testscript/testdata/ui-home.txtar index 0a5c04ab7..126b38e7b 100644 --- a/testscript/testdata/ui-home.txtar +++ b/testscript/testdata/ui-home.txtar @@ -2,8 +2,8 @@ # start soft serve exec soft serve & -# wait for server to start -waitforserver +# wait for SSH server to start +ensureserverrunning SSH_PORT # test repositories tab ui '" q"' diff --git a/testscript/testdata/user_management.txtar b/testscript/testdata/user_management.txtar index f65397090..233e8fd5d 100644 --- a/testscript/testdata/user_management.txtar +++ b/testscript/testdata/user_management.txtar @@ -5,8 +5,8 @@ # start soft serve exec soft serve & -# wait for server to start -waitforserver +# wait for SSH server to start +ensureserverrunning SSH_PORT # add key to admin soft user add-pubkey admin "$ADMIN2_AUTHORIZED_KEY"