8c9777d4de52ad4ab33ad2de6b9c5ca25b4e3059

Author
Ayman Bagabas <ayman.bagabas@gmail.com>
Committer
Ayman Bagabas <ayman.bagabas@gmail.com>
Date

Message

fix(test): tidy testscript and skip ssh-lfs test

Looks like there's a bug with git-lfs making the session hang.

Diff

 1diff --git a/testscript/script_test.go b/testscript/script_test.go
 2index e5623eb539bb8e9737dfa2af7151d94f4d9ed8e7..03a18e67e3389edf68ee8c68505aba72ad4afff4 100644
 3--- a/testscript/script_test.go
 4+++ b/testscript/script_test.go
 5@@ -56,9 +56,6 @@ func TestMain(m *testing.M) {
 6 
 7 	// Run tests
 8 	os.Exit(m.Run())
 9-
10-	// Add binPath to PATH
11-	os.Setenv("PATH", fmt.Sprintf("%s%c%s", os.Getenv("PATH"), os.PathListSeparator, filepath.Dir(binPath)))
12 }
13 
14 func TestScript(t *testing.T) {
15@@ -82,8 +79,8 @@ func TestScript(t *testing.T) {
16 		UpdateScripts:       *update,
17 		RequireExplicitExec: true,
18 		Cmds: map[string]func(ts *testscript.TestScript, neg bool, args []string){
19-			"soft":          cmdSoft(admin1.Signer()),
20-			"usoft":         cmdSoft(user1.Signer()),
21+			"soft":          cmdSoft("admin", admin1.Signer()),
22+			"usoft":         cmdSoft("user1", user1.Signer()),
23 			"git":           cmdGit(key),
24 			"curl":          cmdCurl,
25 			"mkfile":        cmdMkfile,
26@@ -98,7 +95,7 @@ func TestScript(t *testing.T) {
27 		},
28 		Setup: func(e *testscript.Env) error {
29 			// Add binPath to PATH
30-			e.Setenv("PATH", fmt.Sprintf("%s%c%s", filepath.Dir(binPath), os.PathListSeparator, e.Getenv("PATH")))
31+			e.Setenv("PATH", fmt.Sprintf("%s:%s", filepath.Dir(binPath), e.Getenv("PATH")))
32 
33 			data := t.TempDir()
34 			sshPort := test.RandomPort()
35@@ -179,13 +176,13 @@ func TestScript(t *testing.T) {
36 	})
37 }
38 
39-func cmdSoft(key ssh.Signer) func(ts *testscript.TestScript, neg bool, args []string) {
40+func cmdSoft(user string, key ssh.Signer) func(ts *testscript.TestScript, neg bool, args []string) {
41 	return func(ts *testscript.TestScript, neg bool, args []string) {
42 		cli, err := ssh.Dial(
43 			"tcp",
44 			net.JoinHostPort("localhost", ts.Getenv("SSH_PORT")),
45 			&ssh.ClientConfig{
46-				User:            "admin",
47+				User:            user,
48 				Auth:            []ssh.AuthMethod{ssh.PublicKeys(key)},
49 				HostKeyCallback: ssh.InsecureIgnoreHostKey(),
50 			},
51@@ -474,10 +471,11 @@ func cmdCurl(ts *testscript.TestScript, neg bool, args []string) {
52 
53 func cmdWaitforserver(ts *testscript.TestScript, neg bool, args []string) {
54 	// wait until the server is up
55+	addr := net.JoinHostPort("localhost", ts.Getenv("SSH_PORT"))
56 	for {
57 		conn, _ := net.DialTimeout(
58 			"tcp",
59-			net.JoinHostPort("localhost", fmt.Sprintf("%s", ts.Getenv("SSH_PORT"))),
60+			addr,
61 			time.Second,
62 		)
63 		if conn != nil {
64@@ -491,7 +489,7 @@ func cmdStopserver(ts *testscript.TestScript, neg bool, args []string) {
65 	// stop the server
66 	resp, err := http.DefaultClient.Head(fmt.Sprintf("%s/__stop", ts.Getenv("SOFT_SERVE_HTTP_PUBLIC_URL")))
67 	check(ts, err, neg)
68-	defer resp.Body.Close()
69+	resp.Body.Close()
70 	time.Sleep(time.Second * 2) // Allow some time for the server to stop
71 }
72 
73diff --git a/testscript/testdata/http.txtar b/testscript/testdata/http.txtar
74index 662e9b011695f478763f7b9767691b265510e2a1..98f6902a5f08062ac20b671fd705937cab756955 100644
75--- a/testscript/testdata/http.txtar
76+++ b/testscript/testdata/http.txtar
77@@ -47,7 +47,6 @@ git -C repo2 push origin HEAD --tags
78 curl -XGET http://localhost:$HTTP_PORT/repo2.git/info/refs
79 stdout '[0-9a-z]{40}	refs/heads/master\n[0-9a-z]{40}	refs/tags/v0.1.0'
80 
81-
82 # http errors
83 curl -XGET http://localhost:$HTTP_PORT/repo2111foobar.git/foo/bar
84 stdout '404.*'
85diff --git a/testscript/testdata/ssh-lfs.txtar b/testscript/testdata/ssh-lfs.txtar
86index a3753b66a92c44256c4804b1bb21c51a384ce732..fbba49d3ec750a61df2e2a2a35fe7db4e0b24fe2 100644
87--- a/testscript/testdata/ssh-lfs.txtar
88+++ b/testscript/testdata/ssh-lfs.txtar
89@@ -2,6 +2,8 @@
90 
91 [windows] dos2unix err1.txt err2.txt err3.txt errauth.txt
92 
93+skip 'breaks with git-lfs 3.5.1'
94+
95 # enable ssh lfs transfer
96 env SOFT_SERVE_LFS_SSH_ENABLED=true
97 # start soft serve