f99010fae1
CI / lint (push) Failing after 1s
CI / frontend (push) Failing after 1s
CI / scripts (push) Failing after 1s
CI / Go Test (ubuntu-latest) (push) Failing after 0s
CI / frontend-node-25 (push) Failing after 1s
CI / docs (push) Failing after 0s
CI / coverage (push) Failing after 0s
CI / e2e (push) Failing after 0s
Docker / build-and-push (push) Failing after 1s
CI / integration (push) Failing after 4m43s
CI / Go Test (windows-latest) (push) Has been cancelled
CI / Desktop Unit Tests (Windows) (push) Has been cancelled
Desktop Artifacts / Desktop Build (Linux (arm64)) (push) Has been cancelled
Desktop Artifacts / Desktop Build (Linux) (push) Has been cancelled
Desktop Artifacts / Desktop Build (Windows) (push) Has been cancelled
Desktop Artifacts (macOS) / Desktop Build (macOS (aarch64)) (push) Has been cancelled
Desktop Artifacts (macOS) / Desktop Build (macOS (x86_64)) (push) Has been cancelled
73 lines
1.2 KiB
Go
73 lines
1.2 KiB
Go
//go:build sshtest
|
|
|
|
package ssh
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strconv"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
"go.kenn.io/agentsview/internal/db"
|
|
)
|
|
|
|
func testSSHHost(t *testing.T) string {
|
|
t.Helper()
|
|
h := os.Getenv("TEST_SSH_HOST")
|
|
if h == "" {
|
|
h = "localhost"
|
|
}
|
|
return h
|
|
}
|
|
|
|
func testSSHPort(t *testing.T) int {
|
|
t.Helper()
|
|
p := os.Getenv("TEST_SSH_PORT")
|
|
if p == "" {
|
|
p = "2222"
|
|
}
|
|
port, err := strconv.Atoi(p)
|
|
require.NoError(t, err, "invalid TEST_SSH_PORT")
|
|
return port
|
|
}
|
|
|
|
func testSSHUser(t *testing.T) string {
|
|
t.Helper()
|
|
u := os.Getenv("TEST_SSH_USER")
|
|
if u == "" {
|
|
u = "testuser"
|
|
}
|
|
return u
|
|
}
|
|
|
|
func testSSHKeyFile(t *testing.T) string {
|
|
t.Helper()
|
|
k := os.Getenv("TEST_SSH_KEY")
|
|
if k == "" {
|
|
t.Fatal(
|
|
"TEST_SSH_KEY must point to the private key file",
|
|
)
|
|
}
|
|
return k
|
|
}
|
|
|
|
func testSSHOpts(t *testing.T) []string {
|
|
t.Helper()
|
|
keyFile := testSSHKeyFile(t)
|
|
return []string{
|
|
"-i", keyFile,
|
|
"-o", "StrictHostKeyChecking=no",
|
|
"-o", "UserKnownHostsFile=/dev/null",
|
|
}
|
|
}
|
|
|
|
func testDB(t *testing.T) *db.DB {
|
|
t.Helper()
|
|
dbPath := filepath.Join(t.TempDir(), "test.db")
|
|
database, err := db.Open(dbPath)
|
|
require.NoError(t, err, "opening test db")
|
|
t.Cleanup(func() { database.Close() })
|
|
return database
|
|
}
|