Files
kisstron/cli/cli_test.go
T

40 lines
1.0 KiB
Go
Raw Normal View History

2026-09-19 18:26:07 +03:00
package cli
import (
"bufio"
"bytes"
"strings"
"testing"
)
func TestPrintResultSuccess(t *testing.T) {
var buf bytes.Buffer
_ = buf
// PrintResult writes to stdout; capture via the shared writer instead of
// swapping os.Stdout to keep the test hermetic.
got := formatResult(Result{Success: true, Message: "Wallet created"})
want := "Success:\nWallet created\n\n"
if got != want {
t.Fatalf("formatResult = %q, want %q", got, want)
}
}
func TestPrintResultError(t *testing.T) {
got := formatResult(Result{Message: "Invalid private key!"})
want := "Error:\nInvalid private key!\n\n"
if got != want {
t.Fatalf("formatResult = %q, want %q", got, want)
}
}
func TestReadLineTrimsNewline(t *testing.T) {
reader = bufio.NewReader(strings.NewReader("hello\r\n"))
if got := ReadLine(""); got != "hello" {
t.Fatalf("ReadLine = %q, want %q", got, "hello")
}
reader = bufio.NewReader(strings.NewReader("yes\n"))
if got := ReadLine(""); got != "yes" {
t.Fatalf("ReadLine = %q, want %q", got, "yes")
}
}