MCPcopy Create free account
hub / github.com/docker/cli / TestHistoryContext_Table

Function TestHistoryContext_Table

cli/command/image/formatter_history_test.go:196–268  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

194}
195
196func TestHistoryContext_Table(t *testing.T) {
197 out := bytes.NewBufferString("")
198 unixTime := time.Now().AddDate(0, 0, -1).Unix()
199 oldDate := time.Now().AddDate(-17, 0, 0).Unix()
200 histories := client.ImageHistoryResult{
201 Items: []image.HistoryResponseItem{
202 {
203 ID: "imageID1",
204 Created: unixTime,
205 CreatedBy: "/bin/bash ls && npm i && npm run test && karma -c karma.conf.js start && npm start && more commands here && the list goes on",
206 Size: int64(182964289),
207 Comment: "Hi",
208 Tags: []string{"image:tag2"},
209 },
210 {ID: "imageID2", Created: unixTime, CreatedBy: "/bin/bash echo", Size: int64(182964289), Comment: "Hi", Tags: []string{"image:tag2"}},
211 {ID: "imageID3", Created: unixTime, CreatedBy: "/bin/bash ls", Size: int64(182964289), Comment: "Hi", Tags: []string{"image:tag2"}},
212 {ID: "imageID4", Created: unixTime, CreatedBy: "/bin/bash grep", Size: int64(182964289), Comment: "Hi", Tags: []string{"image:tag2"}},
213 {ID: "imageID5", Created: 0, CreatedBy: "/bin/bash echo", Size: int64(182964289), Comment: "Hi", Tags: []string{"image:tag2"}},
214 {ID: "imageID6", Created: oldDate, CreatedBy: "/bin/bash echo", Size: int64(182964289), Comment: "Hi", Tags: []string{"image:tag2"}},
215 },
216 }
217
218 //nolint:dupword // ignore "Duplicate words (CREATED) found"
219 const expectedNoTrunc = `IMAGE CREATED CREATED BY SIZE COMMENT
220imageID1 24 hours ago /bin/bash ls && npm i && npm run test && karma -c karma.conf.js start && npm start && more commands here && the list goes on 183MB Hi
221imageID2 24 hours ago /bin/bash echo 183MB Hi
222imageID3 24 hours ago /bin/bash ls 183MB Hi
223imageID4 24 hours ago /bin/bash grep 183MB Hi
224imageID5 N/A /bin/bash echo 183MB Hi
225imageID6 17 years ago /bin/bash echo 183MB Hi
226`
227 //nolint:dupword // ignore "Duplicate words (CREATED) found"
228 const expectedTrunc = `IMAGE CREATED CREATED BY SIZE COMMENT
229imageID1 24 hours ago /bin/bash ls && npm i && npm run test && kar… 183MB Hi
230imageID2 24 hours ago /bin/bash echo 183MB Hi
231imageID3 24 hours ago /bin/bash ls 183MB Hi
232imageID4 24 hours ago /bin/bash grep 183MB Hi
233imageID5 N/A /bin/bash echo 183MB Hi
234imageID6 17 years ago /bin/bash echo 183MB Hi
235`
236
237 cases := []struct {
238 context formatter.Context
239 expected string
240 }{
241 {
242 formatter.Context{
243 Format: newHistoryFormat("table", false, true),
244 Trunc: true,
245 Output: out,
246 },
247 expectedTrunc,
248 },
249 {
250 formatter.Context{
251 Format: newHistoryFormat("table", false, true),
252 Trunc: false,
253 Output: out,

Callers

nothing calls this directly

Calls 3

newHistoryFormatFunction · 0.85
historyWriteFunction · 0.85
StringMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…