Skip to content

Commit

Permalink
fix(test): tidy testscript and skip ssh-lfs test
Browse files Browse the repository at this point in the history
Looks like there's a bug with git-lfs making the session hang.
  • Loading branch information
aymanbagabas committed Jul 31, 2024
1 parent 621d920 commit 8c9777d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
18 changes: 8 additions & 10 deletions testscript/script_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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,
Expand All @@ -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()
Expand Down Expand Up @@ -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(),
},
Expand Down Expand Up @@ -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 {
Expand All @@ -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
}

Expand Down
1 change: 0 additions & 1 deletion testscript/testdata/http.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -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.*'
Expand Down
2 changes: 2 additions & 0 deletions testscript/testdata/ssh-lfs.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8c9777d

Please sign in to comment.