MCPcopy Index your code
hub / github.com/docker/cli / TestTruncateID

Function TestTruncateID

cli/command/formatter/displayutils_test.go:10–51  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

8)
9
10func TestTruncateID(t *testing.T) {
11 tests := []struct {
12 doc, id, expected string
13 }{
14 {
15 doc: "empty ID",
16 id: "",
17 expected: "",
18 },
19 {
20 // IDs are expected to be 12 (short) or 64 characters, and not be numeric only,
21 // but TruncateID should handle these gracefully.
22 doc: "invalid ID",
23 id: "1234",
24 expected: "1234",
25 },
26 {
27 doc: "full ID",
28 id: "90435eec5c4e124e741ef731e118be2fc799a68aba0466ec17717f24ce2ae6a2",
29 expected: "90435eec5c4e",
30 },
31 {
32 doc: "digest",
33 id: "sha256:90435eec5c4e124e741ef731e118be2fc799a68aba0466ec17717f24ce2ae6a2",
34 expected: "90435eec5c4e",
35 },
36 {
37 doc: "very long ID",
38 id: "90435eec5c4e124e741ef731e118be2fc799a68aba0466ec17717f24ce2ae6a290435eec5c4e124e741ef731e118be2fc799a68aba0466ec17717f24ce2ae6a2",
39 expected: "90435eec5c4e",
40 },
41 }
42
43 for _, tc := range tests {
44 t.Run(tc.doc, func(t *testing.T) {
45 actual := TruncateID(tc.id)
46 if actual != tc.expected {
47 t.Errorf("expected: %q, got: %q", tc.expected, actual)
48 }
49 })
50 }
51}
52
53func TestEllipsis(t *testing.T) {
54 testcases := []struct {

Callers

nothing calls this directly

Calls 1

TruncateIDFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…