test: add basic tests for application
This commit is contained in:
parent
6fcd9dbdc3
commit
07247d68a4
1 changed files with 51 additions and 0 deletions
51
main_test.go
Normal file
51
main_test.go
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"os/exec"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestOpenPopup(t *testing.T) {
|
||||
// Mock tmux command for testing
|
||||
cmd := exec.Command("echo", "mock_session")
|
||||
output, err := cmd.Output()
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to mock tmux command: %v", err)
|
||||
}
|
||||
|
||||
currentSession := strings.TrimSpace(string(output))
|
||||
if currentSession != "mock_session" {
|
||||
t.Errorf("Expected mock_session, got %s", currentSession)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCheckDependencies(t *testing.T) {
|
||||
// Create a mock dependency list for testing
|
||||
mockDeps := []string{"echo", "ls"}
|
||||
|
||||
for _, dep := range mockDeps {
|
||||
cmd := exec.Command(dep, "--version")
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
t.Errorf("Dependency %s check failed: %v", dep, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestRunCmd(t *testing.T) {
|
||||
var stdout, stderr bytes.Buffer
|
||||
cmd := exec.Command("echo", "Hello, World!")
|
||||
cmd.Stdout = &stdout
|
||||
cmd.Stderr = &stderr
|
||||
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
t.Fatalf("runCmd failed: %v", err)
|
||||
}
|
||||
|
||||
if stdout.String() != "Hello, World!\n" {
|
||||
t.Errorf("Expected 'Hello, World!', got %s", stdout.String())
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue