Skip to content

Commit

Permalink
Add test for CLI handling provided stdin input
Browse files Browse the repository at this point in the history
  • Loading branch information
catatsuy committed Mar 20, 2024
1 parent e9d01f7 commit d00c8f6
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"bytes"
"context"
"fmt"
"io"
"os"
"strings"
"testing"

Expand Down Expand Up @@ -42,6 +44,34 @@ func TestRun_versionFlg(t *testing.T) {
}
}

func TestRun_providedStdin(t *testing.T) {
errStream, outStream := new(bytes.Buffer), new(bytes.Buffer)

file, err := os.OpenFile("/dev/tty", os.O_RDONLY, 0)
if err != nil {
t.Fatalf("Failed to open /dev/tty: %v", err)
}
defer file.Close()

var inputStream io.Reader = file

cl := &CLI{
outStream: outStream,
errStream: errStream,
inputStream: inputStream,
}
status := cl.Run([]string{"notify_slack"})

if status != ExitCodeFail {
t.Errorf("ExitStatus=%d, want %d", status, ExitCodeFail)
}

expected := "No input file specified"
if !strings.Contains(errStream.String(), expected) {
t.Errorf("Output=%q, want %q", errStream.String(), expected)
}
}

func TestUploadSnippet(t *testing.T) {
cl := &CLI{
sClient: &fakeSlackClient{},
Expand Down

0 comments on commit d00c8f6

Please sign in to comment.