Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: test framework supports ensuring specific port is open #606

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 27 additions & 17 deletions testscript/script_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -470,16 +470,26 @@ 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",
addr,
time.Second,
)
if conn != nil {
ts.Logf("Server is running on port: %s", port)
conn.Close()
break
}
Expand Down
4 changes: 2 additions & 2 deletions testscript/testdata/anon-access.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions testscript/testdata/help.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions testscript/testdata/http.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions testscript/testdata/jwt.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions testscript/testdata/mirror.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions testscript/testdata/repo-blob.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions testscript/testdata/repo-collab.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions testscript/testdata/repo-commit.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions testscript/testdata/repo-create.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
4 changes: 2 additions & 2 deletions testscript/testdata/repo-delete.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions testscript/testdata/repo-import.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions testscript/testdata/repo-perms.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions testscript/testdata/repo-push.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
4 changes: 2 additions & 2 deletions testscript/testdata/repo-tree.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions testscript/testdata/repo-webhooks.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions testscript/testdata/set-username.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions testscript/testdata/settings.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions testscript/testdata/ssh-lfs.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions testscript/testdata/ssh.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions testscript/testdata/token.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions testscript/testdata/ui-home.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -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"'
Expand Down
4 changes: 2 additions & 2 deletions testscript/testdata/user_management.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading