MCPcopy Index your code
hub / github.com/moby/moby / TestTruncateID

Function TestTruncateID

daemon/internal/stringid/stringid_test.go:15–56  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 3

ErrorfMethod · 0.80
TruncateIDFunction · 0.70
RunMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…