Init commit of jobs output/error message peek project.
This commit is contained in:
parent
c772d7e601
commit
d2b47e3985
38 changed files with 2267 additions and 21 deletions
80
src/frontend/xcecli/cmd/jobs/peek_test.go
Normal file
80
src/frontend/xcecli/cmd/jobs/peek_test.go
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
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)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue