Files
sow-tools/internal/menu/menu_test.go
T
archvillainette 93433e3f53
test-image / build-image (push) Successful in 44s
test / test (push) Successful in 1m20s
build-binaries / build-binaries (push) Successful in 2m0s
build-image / publish (push) Successful in 12s
Cross-Platform Crucible (#2)
Crucible groundwork for cross-platform compatibility.

Reviewed-on: #2
Reviewed-by: xtul <mpiasecki720@protonmail.com>
Co-authored-by: vickydotbat <vickydotbat@tutamail.com>
Co-committed-by: vickydotbat <vickydotbat@tutamail.com>
2026-06-16 13:52:19 +00:00

48 lines
1.3 KiB
Go

package menu
import (
"io"
"reflect"
"strings"
"testing"
)
var sample = []Item{
{Label: "module build", Desc: "build the .mod", Args: []string{"module", "build"}},
{Label: "topdata validate-topdata", Desc: "validate topdata", Args: []string{"topdata", "validate-topdata"}},
}
func TestSelectReturnsChosenArgs(t *testing.T) {
got, err := Select(io.Discard, strings.NewReader("1\n\n"), sample)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if want := []string{"module", "build"}; !reflect.DeepEqual(got, want) {
t.Fatalf("got %v, want %v", got, want)
}
}
func TestSelectAppendsExtraArgs(t *testing.T) {
got, err := Select(io.Discard, strings.NewReader("2\n--dry-run foo\n"), sample)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
want := []string{"topdata", "validate-topdata", "--dry-run", "foo"}
if !reflect.DeepEqual(got, want) {
t.Fatalf("got %v, want %v", got, want)
}
}
func TestSelectQuitReturnsNil(t *testing.T) {
got, err := Select(io.Discard, strings.NewReader("q\n"), sample)
if err != nil || got != nil {
t.Fatalf("quit should return (nil,nil); got (%v,%v)", got, err)
}
}
func TestSelectInvalidErrors(t *testing.T) {
if _, err := Select(io.Discard, strings.NewReader("99\n"), sample); err == nil {
t.Fatal("out-of-range selection should error")
}
}