From 8c9777d4de52ad4ab33ad2de6b9c5ca25b4e3059 Mon Sep 17 00:00:00 2001 From: Ayman Bagabas Date: Tue, 30 Jul 2024 17:53:42 -0400 Subject: [PATCH] fix(test): tidy testscript and skip ssh-lfs test Looks like there's a bug with git-lfs making the session hang. --- testscript/script_test.go | 18 ++++++++---------- testscript/testdata/http.txtar | 1 - testscript/testdata/ssh-lfs.txtar | 2 ++ 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/testscript/script_test.go b/testscript/script_test.go index e5623eb539bb8e9737dfa2af7151d94f4d9ed8e7..03a18e67e3389edf68ee8c68505aba72ad4afff4 100644 --- a/testscript/script_test.go +++ b/testscript/script_test.go @@ -56,9 +56,6 @@ func TestMain(m *testing.M) { // Run tests os.Exit(m.Run()) - - // Add binPath to PATH - os.Setenv("PATH", fmt.Sprintf("%s%c%s", os.Getenv("PATH"), os.PathListSeparator, filepath.Dir(binPath))) } func TestScript(t *testing.T) { @@ -82,8 +79,8 @@ func TestScript(t *testing.T) { UpdateScripts: *update, RequireExplicitExec: true, Cmds: map[string]func(ts *testscript.TestScript, neg bool, args []string){ - "soft": cmdSoft(admin1.Signer()), - "usoft": cmdSoft(user1.Signer()), + "soft": cmdSoft("admin", admin1.Signer()), + "usoft": cmdSoft("user1", user1.Signer()), "git": cmdGit(key), "curl": cmdCurl, "mkfile": cmdMkfile, @@ -98,7 +95,7 @@ func TestScript(t *testing.T) { }, Setup: func(e *testscript.Env) error { // Add binPath to PATH - e.Setenv("PATH", fmt.Sprintf("%s%c%s", filepath.Dir(binPath), os.PathListSeparator, e.Getenv("PATH"))) + e.Setenv("PATH", fmt.Sprintf("%s:%s", filepath.Dir(binPath), e.Getenv("PATH"))) data := t.TempDir() sshPort := test.RandomPort() @@ -179,13 +176,13 @@ func TestScript(t *testing.T) { }) } -func cmdSoft(key ssh.Signer) func(ts *testscript.TestScript, neg bool, args []string) { +func cmdSoft(user string, key ssh.Signer) func(ts *testscript.TestScript, neg bool, args []string) { return func(ts *testscript.TestScript, neg bool, args []string) { cli, err := ssh.Dial( "tcp", net.JoinHostPort("localhost", ts.Getenv("SSH_PORT")), &ssh.ClientConfig{ - User: "admin", + User: user, Auth: []ssh.AuthMethod{ssh.PublicKeys(key)}, HostKeyCallback: ssh.InsecureIgnoreHostKey(), }, @@ -474,10 +471,11 @@ func cmdCurl(ts *testscript.TestScript, neg bool, args []string) { func cmdWaitforserver(ts *testscript.TestScript, neg bool, args []string) { // wait until the server is up + addr := net.JoinHostPort("localhost", ts.Getenv("SSH_PORT")) for { conn, _ := net.DialTimeout( "tcp", - net.JoinHostPort("localhost", fmt.Sprintf("%s", ts.Getenv("SSH_PORT"))), + addr, time.Second, ) if conn != nil { @@ -491,7 +489,7 @@ func cmdStopserver(ts *testscript.TestScript, neg bool, args []string) { // stop the server resp, err := http.DefaultClient.Head(fmt.Sprintf("%s/__stop", ts.Getenv("SOFT_SERVE_HTTP_PUBLIC_URL"))) check(ts, err, neg) - defer resp.Body.Close() + resp.Body.Close() time.Sleep(time.Second * 2) // Allow some time for the server to stop } diff --git a/testscript/testdata/http.txtar b/testscript/testdata/http.txtar index 662e9b011695f478763f7b9767691b265510e2a1..98f6902a5f08062ac20b671fd705937cab756955 100644 --- a/testscript/testdata/http.txtar +++ b/testscript/testdata/http.txtar @@ -47,7 +47,6 @@ git -C repo2 push origin HEAD --tags curl -XGET http://localhost:$HTTP_PORT/repo2.git/info/refs stdout '[0-9a-z]{40} refs/heads/master\n[0-9a-z]{40} refs/tags/v0.1.0' - # http errors curl -XGET http://localhost:$HTTP_PORT/repo2111foobar.git/foo/bar stdout '404.*' diff --git a/testscript/testdata/ssh-lfs.txtar b/testscript/testdata/ssh-lfs.txtar index a3753b66a92c44256c4804b1bb21c51a384ce732..fbba49d3ec750a61df2e2a2a35fe7db4e0b24fe2 100644 --- a/testscript/testdata/ssh-lfs.txtar +++ b/testscript/testdata/ssh-lfs.txtar @@ -2,6 +2,8 @@ [windows] dos2unix err1.txt err2.txt err3.txt errauth.txt +skip 'breaks with git-lfs 3.5.1' + # enable ssh lfs transfer env SOFT_SERVE_LFS_SSH_ENABLED=true # start soft serve