Compare commits

..

No commits in common. "8f1d42b6773363c7d69f1fcda32e76477057ea8e" and "306f19eeae497d3d8d7d3d85cd509727e516fcf2" have entirely different histories.

5 changed files with 61 additions and 113 deletions

View File

@ -9,7 +9,6 @@ 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"
)
@ -131,6 +130,4 @@ func teardown(client *goobs.Client) {
client.Stream.StopStream()
client.Record.StopRecord()
client.Outputs.StopReplayBuffer()
client.Ui.SetStudioModeEnabled(ui.NewSetStudioModeEnabledParams().
WithStudioModeEnabled(false))
}

View File

@ -22,19 +22,7 @@ type RecordStartCmd struct{} // size = 0x0
// Run executes the command to start recording.
func (cmd *RecordStartCmd) Run(ctx *context) error {
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()
_, err := ctx.Client.Record.StartRecord()
if err != nil {
return err
}
@ -47,15 +35,6 @@ 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 TestRecordStart(t *testing.T) {
func TestRecordStartStatusStop(t *testing.T) {
client, disconnect := getClient(t)
defer disconnect()
@ -17,80 +17,51 @@ func TestRecordStart(t *testing.T) {
Out: &out,
}
cmdStatus := &RecordStatusCmd{}
err := cmdStatus.Run(context)
if err != nil {
t.Fatalf("Failed to get recording status: %v", err)
}
var active bool
if out.String() == "Recording is in progress.\n" {
active = true
}
// Reset output buffer for the next command
out.Reset()
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
}
err := cmdStart.Run(context)
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())
t.Fatalf("Expected output to be 'Recording started successfully.', got '%s'", out.String())
}
time.Sleep(1 * time.Second) // Wait for the recording to start
}
// Reset output buffer for the next command
out.Reset()
func TestRecordStop(t *testing.T) {
client, disconnect := getClient(t)
defer disconnect()
var out bytes.Buffer
context := &context{
Client: client,
Out: &out,
}
time.Sleep(1 * time.Second) // Wait for a second to ensure recording has started
cmdStatus := &RecordStatusCmd{}
err := cmdStatus.Run(context)
err = cmdStatus.Run(context)
if err != nil {
t.Fatalf("Failed to get recording status: %v", err)
}
var active bool
if out.String() == "Recording is in progress.\n" {
active = true
if out.String() != "Recording is in progress.\n" {
t.Fatalf("Expected output to be 'Recording is in progress.', got '%s'", out.String())
}
// 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 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 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())
}
time.Sleep(1 * time.Second) // Wait for the recording to stop
}
func TestRecordToggle(t *testing.T) {

View File

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

View File

@ -31,22 +31,21 @@ 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)
}
if out.String() != "Stream started successfully.\n" {
t.Fatalf("Expected output to contain 'Stream started successfully.', got '%s'", out.String())
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())
}
}
time.Sleep(2 * time.Second) // Wait for the stream to start
}
func TestStreamStop(t *testing.T) {
@ -73,22 +72,21 @@ 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)
}
if out.String() != "Stream stopped successfully.\n" {
t.Fatalf("Expected output to contain 'Stream stopped successfully.', got '%s'", out.String())
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())
}
}
time.Sleep(2 * time.Second) // Wait for the stream to stop
}
func TestStreamToggle(t *testing.T) {
@ -119,14 +117,15 @@ 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() != "Stream stopped successfully.\n" {
t.Fatalf("Expected 'Stream stopped successfully.', got: %s", out.String())
if out.String() != "Streaming stopped successfully.\n" {
t.Fatalf("Expected 'Streaming stopped successfully.', got: %s", out.String())
}
} else {
if out.String() != "Stream started successfully.\n" {
t.Fatalf("Expected 'Stream started successfully.', got: %s", out.String())
if out.String() != "Streaming started successfully.\n" {
t.Fatalf("Expected 'Streaming started successfully.', got: %s", out.String())
}
}
time.Sleep(2 * time.Second) // Wait for the stream to toggle
}