Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions pkg/cmd/format_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package cmd

import (
"bytes"
"os"
"strings"
"testing"

"github.com/stretchr/testify/assert"
)

// TestSnapshotListIDNotTruncated guards the snapshot list table: the ID column
// must keep its full width on a narrow terminal so the printed ID can be copied
// into `snapshot get`/`restore`. Truncatable columns (NAME, SOURCE) absorb the
// shrink instead.
func TestSnapshotListIDNotTruncated(t *testing.T) {
os.Setenv("COLUMNS", "40")
defer os.Unsetenv("COLUMNS")

const fullID = "0123456789abcdef01234567" // 24-char snapshot ID

var buf bytes.Buffer
table := NewTableWriter(&buf, "ID", "NAME", "KIND", "SOURCE", "CREATED")
table.TruncOrder = []int{1, 3}
table.AddRow(fullID, "a-very-long-snapshot-name", "memory", "a-very-long-source-instance-name", "3 minutes ago")

widths := table.renderWidths()
assert.Equal(t, len(fullID), widths[0], "ID column should never be shrunk")

table.Render()
assert.True(t, strings.Contains(buf.String(), fullID), "rendered table should contain the full ID")
}
4 changes: 2 additions & 2 deletions pkg/cmd/snapshotcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,14 +343,14 @@ func handleSnapshotList(ctx context.Context, cmd *cli.Command) error {
}

table := NewTableWriter(os.Stdout, "ID", "NAME", "KIND", "SOURCE", "CREATED")
table.TruncOrder = []int{0, 3}
table.TruncOrder = []int{1, 3} // NAME first, then SOURCE; never truncate ID (copy-paste target)
for _, snapshot := range *snapshots {
name := snapshot.Name
if name == "" {
name = "-"
}
table.AddRow(
TruncateID(snapshot.ID),
snapshot.ID,
Comment thread
cursor[bot] marked this conversation as resolved.
name,
string(snapshot.Kind),
snapshot.SourceInstanceName,
Expand Down
Loading