Compare commits

...

4 Commits

Author SHA1 Message Date
8f1d42b677 ensure studio mode disabled at end of tests 2025-05-28 15:39:12 +01:00
620adf7e98 return errors if required
upd tests to reflect changes
2025-05-28 15:38:59 +01:00
4a7b8a074a check current active state before starting/stopping recording
return appropriate errors if required

update tests to reflect changes
2025-05-28 15:33:53 +01:00
0811d711aa split record start/stop tests
test output according to current active state
2025-05-28 14:37:55 +01:00
5 changed files with 114 additions and 62 deletions

View File

@ -9,6 +9,7 @@ import (
"github.com/andreykaipov/goobs/api/requests/filters"
"github.com/andreykaipov/goobs/api/requests/inputs"
"github.com/andreykaipov/goobs/api/requests/scenes"
"github.com/andreykaipov/goobs/api/requests/ui"
typedefs "github.com/andreykaipov/goobs/api/typedefs"
)
@ -130,4 +131,6 @@ func teardown(client *goobs.Client) {
client.Stream.StopStream()
client.Record.StopRecord()
client.Outputs.StopReplayBuffer()
client.Ui.SetStudioModeEnabled(ui.NewSetStudioModeEnabledParams().
WithStudioModeEnabled(false))
}

View File

@ -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

View File

@ -7,7 +7,7 @@ import (
"time"
)
func TestRecordStartStatusStop(t *testing.T) {
func TestRecordStart(t *testing.T) {
client, disconnect := getClient(t)
defer disconnect()
@ -17,51 +17,80 @@ func TestRecordStartStatusStop(t *testing.T) {
Out: &out,
}
cmdStart := &RecordStartCmd{}
err := cmdStart.Run(context)
cmdStatus := &RecordStatusCmd{}
err := cmdStatus.Run(context)
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" {
t.Fatalf("Expected output to be 'Recording started successfully.', got '%s'", out.String())
var active bool
if out.String() == "Recording is in progress.\n" {
active = true
}
// Reset output buffer for the next command
out.Reset()
time.Sleep(1 * time.Second) // Wait for a second to ensure recording has started
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)
}
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) {
client, disconnect := getClient(t)
defer disconnect()
var out bytes.Buffer
context := &context{
Client: client,
Out: &out,
}
cmdStatus := &RecordStatusCmd{}
err = cmdStatus.Run(context)
err := cmdStatus.Run(context)
if err != nil {
t.Fatalf("Failed to get recording status: %v", err)
}
if out.String() != "Recording is in progress.\n" {
t.Fatalf("Expected output to be 'Recording is in progress.', got '%s'", out.String())
var active bool
if out.String() == "Recording is in progress.\n" {
active = true
}
// Reset output buffer for the next command
out.Reset()
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)
}
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
cmdStatus = &RecordStatusCmd{}
err = cmdStatus.Run(context)
if err != nil {
t.Fatalf("Failed to get recording status: %v", err)
}
if out.String() != "Recording is not in progress.\n" {
t.Fatalf("Expected output to be 'Recording is not in progress.', 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) {

View File

@ -23,8 +23,7 @@ func (cmd *StreamStartCmd) Run(ctx *context) error {
return err
}
if status.OutputActive {
fmt.Fprintln(ctx.Out, "Stream is already active.")
return nil
return fmt.Errorf("stream is already in progress")
}
_, err = ctx.Client.Stream.StartStream()
@ -32,7 +31,7 @@ func (cmd *StreamStartCmd) Run(ctx *context) error {
return err
}
fmt.Fprintln(ctx.Out, "Streaming started successfully.")
fmt.Fprintln(ctx.Out, "Stream started successfully.")
return nil
}
@ -47,8 +46,7 @@ func (cmd *StreamStopCmd) Run(ctx *context) error {
return err
}
if !status.OutputActive {
fmt.Fprintln(ctx.Out, "Stream is already inactive.")
return nil
return fmt.Errorf("stream is not in progress")
}
_, err = ctx.Client.Stream.StopStream()
@ -56,7 +54,7 @@ func (cmd *StreamStopCmd) Run(ctx *context) error {
return err
}
fmt.Fprintln(ctx.Out, "Streaming stopped successfully.")
fmt.Fprintln(ctx.Out, "Stream stopped successfully.")
return nil
}
@ -71,9 +69,9 @@ func (cmd *StreamToggleCmd) Run(ctx *context) error {
}
if status.OutputActive {
fmt.Fprintln(ctx.Out, "Streaming started successfully.")
fmt.Fprintln(ctx.Out, "Stream started successfully.")
} else {
fmt.Fprintln(ctx.Out, "Streaming stopped successfully.")
fmt.Fprintln(ctx.Out, "Stream stopped successfully.")
}
return nil
}

View File

@ -31,21 +31,22 @@ func TestStreamStart(t *testing.T) {
cmdStart := &StreamStartCmd{}
err = cmdStart.Run(context)
if active {
if err == nil {
t.Fatalf("Expected error when starting stream while active, got nil")
}
if !strings.Contains(err.Error(), "stream is already in progress") {
t.Fatalf("Expected error message to contain 'stream is already in progress', got '%s'", err.Error())
}
return
}
if err != nil {
t.Fatalf("Failed to start stream: %v", err)
}
time.Sleep(1 * time.Second) // Wait for the stream to start
if active {
if out.String() != "Stream is already active.\n" {
t.Fatalf("Expected 'Stream is already active.', got: %s", out.String())
}
} else {
if out.String() != "Streaming started successfully.\n" {
t.Fatalf("Expected 'Streaming started successfully.', got: %s", out.String())
}
if out.String() != "Stream started successfully.\n" {
t.Fatalf("Expected output to contain 'Stream started successfully.', got '%s'", out.String())
}
time.Sleep(2 * time.Second) // Wait for the stream to start
}
func TestStreamStop(t *testing.T) {
@ -72,21 +73,22 @@ func TestStreamStop(t *testing.T) {
cmdStop := &StreamStopCmd{}
err = cmdStop.Run(context)
if !active {
if err == nil {
t.Fatalf("Expected error when stopping stream while inactive, got nil")
}
if !strings.Contains(err.Error(), "stream is not in progress") {
t.Fatalf("Expected error message to contain 'stream is not in progress', got '%s'", err.Error())
}
return
}
if err != nil {
t.Fatalf("Failed to stop stream: %v", err)
}
time.Sleep(1 * time.Second) // Wait for the stream to stop
if active {
if out.String() != "Streaming stopped successfully.\n" {
t.Fatalf("Expected 'Streaming stopped successfully.', got: %s", out.String())
}
} else {
if out.String() != "Stream is already inactive.\n" {
t.Fatalf("Expected 'Stream is already inactive.', got: %s", out.String())
}
if out.String() != "Stream stopped successfully.\n" {
t.Fatalf("Expected output to contain 'Stream stopped successfully.', got '%s'", out.String())
}
time.Sleep(2 * time.Second) // Wait for the stream to stop
}
func TestStreamToggle(t *testing.T) {
@ -117,15 +119,14 @@ func TestStreamToggle(t *testing.T) {
t.Fatalf("Failed to toggle stream: %v", err)
}
time.Sleep(1 * time.Second) // Wait for the stream to toggle
if active {
if out.String() != "Streaming stopped successfully.\n" {
t.Fatalf("Expected 'Streaming stopped successfully.', got: %s", out.String())
if out.String() != "Stream stopped successfully.\n" {
t.Fatalf("Expected 'Stream stopped successfully.', got: %s", out.String())
}
} else {
if out.String() != "Streaming started successfully.\n" {
t.Fatalf("Expected 'Streaming started successfully.', got: %s", out.String())
if out.String() != "Stream started successfully.\n" {
t.Fatalf("Expected 'Stream started successfully.', got: %s", out.String())
}
}
time.Sleep(2 * time.Second) // Wait for the stream to toggle
}