Skip to content

Commit

Permalink
fix: cleanup test emissions
Browse files Browse the repository at this point in the history
  • Loading branch information
aymanbagabas committed Apr 24, 2023
1 parent f45b56f commit 59b452f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
14 changes: 5 additions & 9 deletions git/git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package git
import (
"fmt"
"net"
"os"
"os/exec"
"path/filepath"
"runtime"
Expand All @@ -17,6 +16,7 @@ import (

func TestGitMiddleware(t *testing.T) {
pubkey, pkPath := createKeyPair(t)
hkPath := filepath.Join(t.TempDir(), "id_ed25519")

l, err := net.Listen("tcp", "127.0.0.1:0")
requireNoError(t, err)
Expand All @@ -39,6 +39,7 @@ func TestGitMiddleware(t *testing.T) {
},
}
srv, err := wish.NewServer(
wish.WithHostKeyPath(hkPath),
wish.WithMiddleware(Middleware(repoDir, hooks)),
wish.WithPublicKeyAuth(func(ctx ssh.Context, key ssh.PublicKey) bool {
return true
Expand Down Expand Up @@ -194,15 +195,10 @@ func requireHasAction(t *testing.T, actions []action, key ssh.PublicKey, repo st
func createKeyPair(t *testing.T) (ssh.PublicKey, string) {
t.Helper()

keyDir := t.TempDir()
_, err := keygen.New(filepath.Join(keyDir, "id_ed25519"), keygen.WithKeyType(keygen.Ed25519), keygen.WithWrite())
pk := filepath.Join(t.TempDir(), "id_ed25519")
kp, err := keygen.New(pk, keygen.WithKeyType(keygen.Ed25519), keygen.WithWrite())
requireNoError(t, err)
pk := filepath.Join(keyDir, "id_ed25519")
pubBytes, err := os.ReadFile(filepath.Join(keyDir, "id_ed25519.pub"))
requireNoError(t, err)
pubkey, _, _, _, err := ssh.ParseAuthorizedKey(pubBytes)
requireNoError(t, err)
return pubkey, pk
return kp.PublicKey(), pk
}

type accessDetails struct {
Expand Down
11 changes: 7 additions & 4 deletions wish_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package wish
import (
"bytes"
"errors"
"path/filepath"
"strings"
"testing"
"time"
Expand All @@ -13,18 +14,20 @@ import (
)

func TestNewServer(t *testing.T) {
_, err := NewServer()
fp := filepath.Join(t.TempDir(), "id_ed25519")
_, err := NewServer(WithHostKeyPath(fp))
if err != nil {
t.Fatal(err)
}
}

func TestNewServerWithOptions(t *testing.T) {
_, err := NewServer(
fp := filepath.Join(t.TempDir(), "id_ed25519")
if _, err := NewServer(
WithHostKeyPath(fp),
WithMaxTimeout(time.Second),
WithAddress(":2222"),
)
if err != nil {
); err != nil {
t.Fatal(err)
}
}
Expand Down

0 comments on commit 59b452f

Please sign in to comment.