mirror of
https://github.com/onyx-and-iris/gobs-cli.git
synced 2025-06-09 13:10:35 +01:00
check current active state before starting/stopping recording
return appropriate errors if required update tests to reflect changes
This commit is contained in:
parent
0811d711aa
commit
4a7b8a074a
23
record.go
23
record.go
@ -22,7 +22,19 @@ type RecordStartCmd struct{} // size = 0x0
|
||||
|
||||
// Run executes the command to start recording.
|
||||
func (cmd *RecordStartCmd) Run(ctx *context) error {
|
||||
_, err := ctx.Client.Record.StartRecord()
|
||||
status, err := ctx.Client.Record.GetRecordStatus()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if status.OutputActive {
|
||||
if status.OutputPaused {
|
||||
return fmt.Errorf("recording is already in progress and paused")
|
||||
}
|
||||
return fmt.Errorf("recording is already in progress")
|
||||
}
|
||||
|
||||
_, err = ctx.Client.Record.StartRecord()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -35,6 +47,15 @@ type RecordStopCmd struct{} // size = 0x0
|
||||
|
||||
// Run executes the command to stop recording.
|
||||
func (cmd *RecordStopCmd) Run(ctx *context) error {
|
||||
status, err := ctx.Client.Record.GetRecordStatus()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if !status.OutputActive {
|
||||
return fmt.Errorf("recording is not in progress")
|
||||
}
|
||||
|
||||
resp, err := ctx.Client.Record.StopRecord()
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -31,19 +31,23 @@ func TestRecordStart(t *testing.T) {
|
||||
|
||||
cmdStart := &RecordStartCmd{}
|
||||
err = cmdStart.Run(context)
|
||||
if active {
|
||||
if err == nil {
|
||||
t.Fatalf("Expected error when starting recording while active, got nil")
|
||||
}
|
||||
if !strings.Contains(err.Error(), "Recording is already in progress") {
|
||||
t.Fatalf("Expected error message to contain 'Recording is already in progress', got '%s'", err.Error())
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
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
|
||||
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())
|
||||
}
|
||||
if out.String() != "Recording started successfully.\n" {
|
||||
t.Fatalf("Expected output to contain 'Recording started successfully.', got '%s'", out.String())
|
||||
}
|
||||
time.Sleep(1 * time.Second) // Wait for the recording to start
|
||||
}
|
||||
|
||||
func TestRecordStop(t *testing.T) {
|
||||
@ -70,19 +74,23 @@ func TestRecordStop(t *testing.T) {
|
||||
|
||||
cmdStop := &RecordStopCmd{}
|
||||
err = cmdStop.Run(context)
|
||||
if !active {
|
||||
if err == nil {
|
||||
t.Fatalf("Expected error when stopping recording while inactive, got nil")
|
||||
}
|
||||
if !strings.Contains(err.Error(), "recording is not in progress") {
|
||||
t.Fatalf("Expected error message to contain 'recording is not in progress', got '%s'", err.Error())
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to stop recording: %v", err)
|
||||
}
|
||||
time.Sleep(1 * time.Second) // Wait for a second to ensure recording has stopped
|
||||
if !active {
|
||||
if out.String() != "No recording is currently in progress.\n" {
|
||||
t.Fatalf("Expected output to be 'No recording is currently in progress.', got '%s'", out.String())
|
||||
}
|
||||
} else {
|
||||
if !strings.Contains(out.String(), "Recording stopped successfully. Output file:") {
|
||||
t.Fatalf("Expected output to contain 'Recording stopped successfully. Output file:', got '%s'", out.String())
|
||||
}
|
||||
if !strings.Contains(out.String(), "Recording stopped successfully. Output file: ") {
|
||||
t.Fatalf("Expected output to contain 'Recording stopped successfully. Output file: ', got '%s'", out.String())
|
||||
}
|
||||
time.Sleep(1 * time.Second) // Wait for the recording to stop
|
||||
}
|
||||
|
||||
func TestRecordToggle(t *testing.T) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user