Don't display node name if output isn't verbose. Add tests.
This commit is contained in:
parent
9470507cf4
commit
1272fcb9e1
|
@ -120,9 +120,11 @@ func TestAllocStatusCommand_Run(t *testing.T) {
|
|||
}
|
||||
// get an alloc id
|
||||
allocId1 := ""
|
||||
nodeName := ""
|
||||
if allocs, _, err := client.Jobs().Allocations(jobID, false, nil); err == nil {
|
||||
if len(allocs) > 0 {
|
||||
allocId1 = allocs[0].ID
|
||||
nodeName = allocs[0].NodeName
|
||||
}
|
||||
}
|
||||
if allocId1 == "" {
|
||||
|
@ -141,6 +143,16 @@ func TestAllocStatusCommand_Run(t *testing.T) {
|
|||
t.Fatalf("expected to have 'Modified' but saw: %s", out)
|
||||
}
|
||||
|
||||
if !strings.Contains(out, "Modified") {
|
||||
t.Fatalf("expected to have 'Modified' but saw: %s", out)
|
||||
}
|
||||
|
||||
nodeNameRegexpStr := fmt.Sprintf(`\nNode Name\s+= %s\n`, regexp.QuoteMeta(nodeName))
|
||||
nodeNameRegexp := regexp.MustCompile(nodeNameRegexpStr)
|
||||
if !nodeNameRegexp.MatchString(out) {
|
||||
t.Fatalf("expected to have 'Node Name' but saw: %s", out)
|
||||
}
|
||||
|
||||
ui.OutputWriter.Reset()
|
||||
|
||||
if code := cmd.Run([]string{"-address=" + url, "-verbose", allocId1}); code != 0 {
|
||||
|
|
|
@ -428,15 +428,14 @@ func formatAllocListStubs(stubs []*api.AllocationListStub, verbose bool, uuidLen
|
|||
formatUnixNanoTime(alloc.ModifyTime))
|
||||
}
|
||||
} else {
|
||||
allocs[0] = "ID|Node ID|Node Name|Task Group|Version|Desired|Status|Created|Modified"
|
||||
allocs[0] = "ID|Node ID|Task Group|Version|Desired|Status|Created|Modified"
|
||||
for i, alloc := range stubs {
|
||||
now := time.Now()
|
||||
createTimePretty := prettyTimeDiff(time.Unix(0, alloc.CreateTime), now)
|
||||
modTimePretty := prettyTimeDiff(time.Unix(0, alloc.ModifyTime), now)
|
||||
allocs[i+1] = fmt.Sprintf("%s|%s|%s|%s|%d|%s|%s|%s|%s",
|
||||
allocs[i+1] = fmt.Sprintf("%s|%s|%s|%d|%s|%s|%s|%s",
|
||||
limit(alloc.ID, uuidLength),
|
||||
limit(alloc.NodeID, uuidLength),
|
||||
alloc.NodeName,
|
||||
alloc.TaskGroup,
|
||||
alloc.JobVersion,
|
||||
alloc.DesiredStatus,
|
||||
|
|
|
@ -2,6 +2,7 @@ package command
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
@ -123,6 +124,14 @@ func TestJobStatusCommand_Run(t *testing.T) {
|
|||
if code := cmd.Run([]string{"-address=" + url, "-verbose", "job2_sfx"}); code != 0 {
|
||||
t.Fatalf("expected exit 0, got: %d", code)
|
||||
}
|
||||
|
||||
nodeName := ""
|
||||
if allocs, _, err := client.Jobs().Allocations("job2_sfx", false, nil); err == nil {
|
||||
if len(allocs) > 0 {
|
||||
nodeName = allocs[0].NodeName
|
||||
}
|
||||
}
|
||||
|
||||
out = ui.OutputWriter.String()
|
||||
if strings.Contains(out, "job1_sfx") || !strings.Contains(out, "job2_sfx") {
|
||||
t.Fatalf("expected only job2_sfx, got: %s", out)
|
||||
|
@ -139,6 +148,18 @@ func TestJobStatusCommand_Run(t *testing.T) {
|
|||
if !strings.Contains(out, "Modified") {
|
||||
t.Fatal("should have modified header")
|
||||
}
|
||||
|
||||
// string calculations based on 1-byte chars, not using runes
|
||||
allocationsTableName := "Allocations\n"
|
||||
allocationsTableStr := strings.Split(out, allocationsTableName)[1]
|
||||
nodeNameHeaderStr := "Node Name"
|
||||
nodeNameHeaderIndex := strings.Index(allocationsTableStr, nodeNameHeaderStr)
|
||||
nodeNameRegexpStr := fmt.Sprintf(`.*%s.*\n.{%d}%s`, nodeNameHeaderStr, nodeNameHeaderIndex, regexp.QuoteMeta(nodeName))
|
||||
nodeNameRegexp := regexp.MustCompile(nodeNameRegexpStr)
|
||||
if !nodeNameRegexp.MatchString(out) {
|
||||
t.Fatalf("expected to have 'Node Name' but saw: %s", out)
|
||||
}
|
||||
|
||||
ui.ErrorWriter.Reset()
|
||||
ui.OutputWriter.Reset()
|
||||
|
||||
|
|
Loading…
Reference in New Issue