mirror of
https://github.com/onyx-and-iris/gobs-cli.git
synced 2025-06-09 13:10:35 +01:00
return errors if required
upd tests to reflect changes
This commit is contained in:
parent
4a7b8a074a
commit
620adf7e98
14
stream.go
14
stream.go
@ -23,8 +23,7 @@ func (cmd *StreamStartCmd) Run(ctx *context) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if status.OutputActive {
|
if status.OutputActive {
|
||||||
fmt.Fprintln(ctx.Out, "Stream is already active.")
|
return fmt.Errorf("stream is already in progress")
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = ctx.Client.Stream.StartStream()
|
_, err = ctx.Client.Stream.StartStream()
|
||||||
@ -32,7 +31,7 @@ func (cmd *StreamStartCmd) Run(ctx *context) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Fprintln(ctx.Out, "Streaming started successfully.")
|
fmt.Fprintln(ctx.Out, "Stream started successfully.")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,8 +46,7 @@ func (cmd *StreamStopCmd) Run(ctx *context) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if !status.OutputActive {
|
if !status.OutputActive {
|
||||||
fmt.Fprintln(ctx.Out, "Stream is already inactive.")
|
return fmt.Errorf("stream is not in progress")
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = ctx.Client.Stream.StopStream()
|
_, err = ctx.Client.Stream.StopStream()
|
||||||
@ -56,7 +54,7 @@ func (cmd *StreamStopCmd) Run(ctx *context) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Fprintln(ctx.Out, "Streaming stopped successfully.")
|
fmt.Fprintln(ctx.Out, "Stream stopped successfully.")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,9 +69,9 @@ func (cmd *StreamToggleCmd) Run(ctx *context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if status.OutputActive {
|
if status.OutputActive {
|
||||||
fmt.Fprintln(ctx.Out, "Streaming started successfully.")
|
fmt.Fprintln(ctx.Out, "Stream started successfully.")
|
||||||
} else {
|
} else {
|
||||||
fmt.Fprintln(ctx.Out, "Streaming stopped successfully.")
|
fmt.Fprintln(ctx.Out, "Stream stopped successfully.")
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -31,21 +31,22 @@ func TestStreamStart(t *testing.T) {
|
|||||||
|
|
||||||
cmdStart := &StreamStartCmd{}
|
cmdStart := &StreamStartCmd{}
|
||||||
err = cmdStart.Run(context)
|
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 {
|
if err != nil {
|
||||||
t.Fatalf("Failed to start stream: %v", err)
|
t.Fatalf("Failed to start stream: %v", err)
|
||||||
}
|
}
|
||||||
|
if out.String() != "Stream started successfully.\n" {
|
||||||
time.Sleep(1 * time.Second) // Wait for the stream to start
|
t.Fatalf("Expected output to contain 'Stream started successfully.', got '%s'", out.String())
|
||||||
|
|
||||||
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) {
|
func TestStreamStop(t *testing.T) {
|
||||||
@ -72,21 +73,22 @@ func TestStreamStop(t *testing.T) {
|
|||||||
|
|
||||||
cmdStop := &StreamStopCmd{}
|
cmdStop := &StreamStopCmd{}
|
||||||
err = cmdStop.Run(context)
|
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 {
|
if err != nil {
|
||||||
t.Fatalf("Failed to stop stream: %v", err)
|
t.Fatalf("Failed to stop stream: %v", err)
|
||||||
}
|
}
|
||||||
|
if out.String() != "Stream stopped successfully.\n" {
|
||||||
time.Sleep(1 * time.Second) // Wait for the stream to stop
|
t.Fatalf("Expected output to contain 'Stream stopped successfully.', got '%s'", out.String())
|
||||||
|
|
||||||
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) {
|
func TestStreamToggle(t *testing.T) {
|
||||||
@ -117,15 +119,14 @@ func TestStreamToggle(t *testing.T) {
|
|||||||
t.Fatalf("Failed to toggle stream: %v", err)
|
t.Fatalf("Failed to toggle stream: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
time.Sleep(1 * time.Second) // Wait for the stream to toggle
|
|
||||||
|
|
||||||
if active {
|
if active {
|
||||||
if out.String() != "Streaming stopped successfully.\n" {
|
if out.String() != "Stream stopped successfully.\n" {
|
||||||
t.Fatalf("Expected 'Streaming stopped successfully.', got: %s", out.String())
|
t.Fatalf("Expected 'Stream stopped successfully.', got: %s", out.String())
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if out.String() != "Streaming started successfully.\n" {
|
if out.String() != "Stream started successfully.\n" {
|
||||||
t.Fatalf("Expected 'Streaming started successfully.', got: %s", out.String())
|
t.Fatalf("Expected 'Stream started successfully.', got: %s", out.String())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
time.Sleep(2 * time.Second) // Wait for the stream to toggle
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user