80 lines
1.6 KiB
Go
80 lines
1.6 KiB
Go
package jobs
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"xcecli/common/format"
|
|
)
|
|
|
|
func TestPeekJobIDParsing(t *testing.T) {
|
|
tests := []struct {
|
|
input string
|
|
wantAPI string
|
|
}{
|
|
{"12345", "12345"},
|
|
{"12345[0]", "12345[0]"},
|
|
{"12345[2]", "12345[2]"},
|
|
{"plain_id", "plain_id"}, // ToAPIJobID passes through non-numeric strings
|
|
}
|
|
|
|
for _, tc := range tests {
|
|
t.Run(tc.input, func(t *testing.T) {
|
|
apiID, err := format.ToAPIJobID(tc.input)
|
|
if err != nil {
|
|
t.Fatalf("unexpected error: %v", err)
|
|
}
|
|
if apiID != tc.wantAPI {
|
|
t.Errorf("apiID = %q, want %q", apiID, tc.wantAPI)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestPeekDefaults(t *testing.T) {
|
|
q := NewPeekQuerier(nil)
|
|
if q.lines != 100 {
|
|
t.Errorf("default lines = %d, want 100", q.lines)
|
|
}
|
|
if q.stderr {
|
|
t.Error("default stderr should be false")
|
|
}
|
|
if q.noFollow {
|
|
t.Error("default noFollow should be false")
|
|
}
|
|
}
|
|
|
|
func TestPeekStreamType(t *testing.T) {
|
|
q := NewPeekQuerier(nil)
|
|
|
|
streamType := "stdout"
|
|
if q.stderr {
|
|
streamType = "stderr"
|
|
}
|
|
if streamType != "stdout" {
|
|
t.Errorf("default stream type = %q, want stdout", streamType)
|
|
}
|
|
|
|
q2 := NewPeekQuerier(nil)
|
|
q2.stderr = true
|
|
streamType = "stdout"
|
|
if q2.stderr {
|
|
streamType = "stderr"
|
|
}
|
|
if streamType != "stderr" {
|
|
t.Errorf("stderr stream type = %q, want stderr", streamType)
|
|
}
|
|
}
|
|
|
|
func TestPeekCommand_NoJobID(t *testing.T) {
|
|
q := NewPeekQuerier(nil)
|
|
|
|
err := q.Run("")
|
|
if err == nil {
|
|
t.Error("expected error for empty job ID")
|
|
}
|
|
// Should fail on job ID parsing, not on config
|
|
if !strings.Contains(strings.ToLower(err.Error()), "invalid") {
|
|
t.Logf("error message (may vary): %v", err)
|
|
}
|
|
}
|