return errors if required

upd tests to reflect changes
This commit is contained in:
onyx-and-iris 2025-05-28 15:38:59 +01:00
parent 4a7b8a074a
commit 620adf7e98
2 changed files with 35 additions and 36 deletions

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
}