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

Function TestImageContextWrite

cli/command/formatter/image_test.go:99–312  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

97}
98
99func TestImageContextWrite(t *testing.T) {
100 unixTime := time.Now().AddDate(0, 0, -1).Unix()
101 zeroTime := int64(-62135596800)
102 expectedTime := time.Unix(unixTime, 0).String()
103 expectedZeroTime := time.Unix(zeroTime, 0).String()
104
105 cases := []struct {
106 context ImageContext
107 expected string
108 }{
109 // Errors
110 {
111 ImageContext{
112 Context: Context{
113 Format: "{{InvalidFunction}}",
114 },
115 },
116 `template parsing error: template: :1: function "InvalidFunction" not defined`,
117 },
118 {
119 ImageContext{
120 Context: Context{
121 Format: "{{nil}}",
122 },
123 },
124 `template parsing error: template: :1:2: executing "" at <nil>: nil is not a command`,
125 },
126 // Table Format
127 {
128 ImageContext{
129 Context: Context{
130 Format: NewImageFormat("table", false, false),
131 },
132 },
133 `REPOSITORY TAG IMAGE ID CREATED SIZE
134image tag1 imageID1 24 hours ago 0B
135image tag2 imageID2 N/A 0B
136<none> <none> imageID3 24 hours ago 0B
137`,
138 },
139 {
140 ImageContext{
141 Context: Context{
142 Format: NewImageFormat("table {{.Repository}}", false, false),
143 },
144 },
145 "REPOSITORY\nimage\nimage\n<none>\n", //nolint:dupword // ignore "Duplicate words (image) found"
146 },
147 {
148 ImageContext{
149 Context: Context{
150 Format: NewImageFormat("table {{.Repository}}", false, true),
151 },
152 Digest: true,
153 },
154 `REPOSITORY DIGEST
155image sha256:cbbf2f9a99b47fc460d422812b6a5adff7dfee951d8fa2e4a98caa0382cfbdbf
156image <none>

Callers

nothing calls this directly

Calls 4

NewImageFormatFunction · 0.85
ImageWriteFunction · 0.85
StringMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…