(t *testing.T)
| 97 | } |
| 98 | |
| 99 | func 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 |
| 134 | image tag1 imageID1 24 hours ago 0B |
| 135 | image 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 |
| 155 | image sha256:cbbf2f9a99b47fc460d422812b6a5adff7dfee951d8fa2e4a98caa0382cfbdbf |
| 156 | image <none> |
nothing calls this directly
no test coverage detected
searching dependent graphs…