(t *testing.T)
| 126 | } |
| 127 | |
| 128 | func TestSearchContextWrite(t *testing.T) { |
| 129 | cases := []struct { |
| 130 | doc string |
| 131 | format formatter.Format |
| 132 | expected string |
| 133 | expectedErr string |
| 134 | }{ |
| 135 | { |
| 136 | doc: "Errors", |
| 137 | format: "{{InvalidFunction}}", |
| 138 | expectedErr: `template parsing error: template: :1: function "InvalidFunction" not defined`, |
| 139 | }, |
| 140 | { |
| 141 | doc: "Nil format", |
| 142 | format: "{{nil}}", |
| 143 | expectedErr: `template parsing error: template: :1:2: executing "" at <nil>: nil is not a command`, |
| 144 | }, |
| 145 | { |
| 146 | doc: "JSON format", |
| 147 | format: "{{json .}}", |
| 148 | expected: `{"Description":"Official build","IsOfficial":"true","Name":"result1","StarCount":"5000"} |
| 149 | {"Description":"Not official","IsOfficial":"false","Name":"result2","StarCount":"5"} |
| 150 | `, |
| 151 | }, |
| 152 | { |
| 153 | doc: "JSON format, single field", |
| 154 | format: "{{json .Name}}", |
| 155 | expected: `"result1" |
| 156 | "result2" |
| 157 | `, |
| 158 | }, |
| 159 | { |
| 160 | doc: "Table format", |
| 161 | format: newFormat("table"), |
| 162 | expected: string(golden.Get(t, "search-context-write-table.golden")), |
| 163 | }, |
| 164 | { |
| 165 | doc: "Table format, single column", |
| 166 | format: newFormat("table {{.Name}}"), |
| 167 | expected: `NAME |
| 168 | result1 |
| 169 | result2 |
| 170 | `, |
| 171 | }, |
| 172 | { |
| 173 | doc: "Custom format, single field", |
| 174 | format: newFormat("{{.Name}}"), |
| 175 | expected: `result1 |
| 176 | result2 |
| 177 | `, |
| 178 | }, |
| 179 | { |
| 180 | doc: "Custom Format, two columns", |
| 181 | format: newFormat("{{.Name}} {{.StarCount}}"), |
| 182 | expected: `result1 5000 |
| 183 | result2 5 |
| 184 | `, |
| 185 | }, |
nothing calls this directly
no test coverage detected
searching dependent graphs…