split record start/stop tests

test output according to current active state
This commit is contained in:
onyx-and-iris 2025-05-28 14:37:55 +01:00
parent 306f19eeae
commit 0811d711aa

View File

@ -7,7 +7,7 @@ import (
"time" "time"
) )
func TestRecordStartStatusStop(t *testing.T) { func TestRecordStart(t *testing.T) {
client, disconnect := getClient(t) client, disconnect := getClient(t)
defer disconnect() defer disconnect()
@ -17,26 +17,53 @@ func TestRecordStartStatusStop(t *testing.T) {
Out: &out, Out: &out,
} }
cmdStart := &RecordStartCmd{} cmdStatus := &RecordStatusCmd{}
err := cmdStart.Run(context) err := cmdStatus.Run(context)
if err != nil { if err != nil {
t.Fatalf("Failed to start recording: %v", err) t.Fatalf("Failed to get recording status: %v", err)
} }
if out.String() != "Recording started successfully.\n" { var active bool
t.Fatalf("Expected output to be 'Recording started successfully.', got '%s'", out.String()) if out.String() == "Recording is in progress.\n" {
active = true
} }
// Reset output buffer for the next command // Reset output buffer for the next command
out.Reset() out.Reset()
cmdStart := &RecordStartCmd{}
err = cmdStart.Run(context)
if err != nil {
t.Fatalf("Failed to start recording: %v", err)
}
time.Sleep(1 * time.Second) // Wait for a second to ensure recording has started time.Sleep(1 * time.Second) // Wait for a second to ensure recording has started
if active {
if out.String() != "Recording is already in progress.\n" {
t.Fatalf("Expected output to be 'Recording is already in progress.', got '%s'", out.String())
}
} else {
if !strings.Contains(out.String(), "Recording started successfully.") {
t.Fatalf("Expected output to contain 'Recording started successfully.', got '%s'", out.String())
}
}
}
func TestRecordStop(t *testing.T) {
client, disconnect := getClient(t)
defer disconnect()
var out bytes.Buffer
context := &context{
Client: client,
Out: &out,
}
cmdStatus := &RecordStatusCmd{} cmdStatus := &RecordStatusCmd{}
err = cmdStatus.Run(context) err := cmdStatus.Run(context)
if err != nil { if err != nil {
t.Fatalf("Failed to get recording status: %v", err) t.Fatalf("Failed to get recording status: %v", err)
} }
if out.String() != "Recording is in progress.\n" { var active bool
t.Fatalf("Expected output to be 'Recording is in progress.', got '%s'", out.String()) if out.String() == "Recording is in progress.\n" {
active = true
} }
// Reset output buffer for the next command // Reset output buffer for the next command
out.Reset() out.Reset()
@ -46,21 +73,15 @@ func TestRecordStartStatusStop(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("Failed to stop recording: %v", err) t.Fatalf("Failed to stop recording: %v", err)
} }
if !strings.Contains(out.String(), "Recording stopped successfully. Output file:") {
t.Fatalf("Expected output to be 'Recording stopped successfully.', got '%s'", out.String())
}
// Reset output buffer for the next command
out.Reset()
time.Sleep(1 * time.Second) // Wait for a second to ensure recording has stopped time.Sleep(1 * time.Second) // Wait for a second to ensure recording has stopped
if !active {
cmdStatus = &RecordStatusCmd{} if out.String() != "No recording is currently in progress.\n" {
err = cmdStatus.Run(context) t.Fatalf("Expected output to be 'No recording is currently in progress.', got '%s'", out.String())
if err != nil { }
t.Fatalf("Failed to get recording status: %v", err) } else {
} if !strings.Contains(out.String(), "Recording stopped successfully. Output file:") {
if out.String() != "Recording is not in progress.\n" { t.Fatalf("Expected output to contain 'Recording stopped successfully. Output file:', got '%s'", out.String())
t.Fatalf("Expected output to be 'Recording is not in progress.', got '%s'", out.String()) }
} }
} }