updated tests
Some checks failed
Run Integration Tests / test (push) Failing after 19s

This commit is contained in:
partisan 2025-01-08 01:14:10 +01:00
parent 27c29c185a
commit dfb8c35bc6

View file

@ -2,7 +2,6 @@ package tests
import (
"bufio"
"context"
"crypto/rand"
"encoding/json"
"fmt"
@ -10,9 +9,7 @@ import (
"math/big"
"net/http"
"net/url"
"os"
"os/exec"
"path/filepath"
"sync"
"syscall"
"testing"
@ -56,50 +53,27 @@ func TestApplication(t *testing.T) {
// Ensure the test runs from the root directory
rootDir := "../" // Path to the root directory of the repository
// Build the application using `run.sh --build`
buildCmd := exec.Command("sh", "./run.sh", "--build")
buildCmd.Dir = rootDir
buildOutput, err := buildCmd.CombinedOutput()
if err != nil {
t.Fatalf("Failed to build application: %v\nOutput:\n%s", err, string(buildOutput))
}
t.Log("Application built successfully")
// Path to the built executable relative to rootDir
executablePath := "./qgato" // Since cmd.Dir is rootDir, this path is relative to rootDir
// Ensure the executable has execute permissions
execFullPath := filepath.Join(rootDir, "qgato")
if err := os.Chmod(execFullPath, 0755); err != nil {
t.Fatalf("Failed to set execute permissions on the executable: %v", err)
}
// Create a context with cancellation
ctx, cancel := context.WithCancel(context.Background())
defer cancel() // Ensure resources are cleaned up
// Start the application using the built executable
cmd := exec.CommandContext(ctx, executablePath, "--skip-config-check")
cmd.Dir = rootDir // Set the working directory to the root directory
// Run the application using `run.sh`
runCmd := exec.Command("sh", "./run.sh", "--skip-config-check")
runCmd.Dir = rootDir
// Set process group ID so we can kill it and its children
cmd.SysProcAttr = &syscall.SysProcAttr{
runCmd.SysProcAttr = &syscall.SysProcAttr{
Setpgid: true,
}
// Capture application output for logging
appStdout, err := cmd.StdoutPipe()
appStdout, err := runCmd.StdoutPipe()
if err != nil {
t.Fatalf("Failed to capture stdout: %v", err)
}
appStderr, err := cmd.StderrPipe()
appStderr, err := runCmd.StderrPipe()
if err != nil {
t.Fatalf("Failed to capture stderr: %v", err)
}
// Start the application
if err := cmd.Start(); err != nil {
if err := runCmd.Start(); err != nil {
t.Fatalf("Failed to start application: %v", err)
}
@ -120,14 +94,14 @@ func TestApplication(t *testing.T) {
// Defer cleanup to ensure process is killed after the test
defer func() {
// Kill the process group
pgid, err := syscall.Getpgid(cmd.Process.Pid)
pgid, err := syscall.Getpgid(runCmd.Process.Pid)
if err == nil {
syscall.Kill(-pgid, syscall.SIGKILL)
} else {
t.Logf("Failed to get process group ID: %v", err)
cmd.Process.Kill()
runCmd.Process.Kill()
}
cmd.Wait()
runCmd.Wait()
// Print summary
printSummary(summary, t)
@ -141,7 +115,7 @@ func TestApplication(t *testing.T) {
t.Log("Application is running")
// Create a process instance for the application
appProcess, err := process.NewProcess(int32(cmd.Process.Pid))
appProcess, err := process.NewProcess(int32(runCmd.Process.Pid))
if err != nil {
t.Fatalf("Failed to create process instance: %v", err)
}