(t *testing.T)
| 240 | } |
| 241 | |
| 242 | func TestServiceContextWriteJSON(t *testing.T) { |
| 243 | services := client.ServiceListResult{ |
| 244 | Items: []swarm.Service{ |
| 245 | { |
| 246 | ID: "01_baz", |
| 247 | Spec: swarm.ServiceSpec{ |
| 248 | Annotations: swarm.Annotations{Name: "baz"}, |
| 249 | Mode: swarm.ServiceMode{ |
| 250 | Global: &swarm.GlobalService{}, |
| 251 | }, |
| 252 | }, |
| 253 | Endpoint: swarm.Endpoint{ |
| 254 | Ports: []swarm.PortConfig{ |
| 255 | { |
| 256 | PublishMode: "ingress", |
| 257 | PublishedPort: 80, |
| 258 | TargetPort: 8080, |
| 259 | Protocol: "tcp", |
| 260 | }, |
| 261 | }, |
| 262 | }, |
| 263 | ServiceStatus: &swarm.ServiceStatus{ |
| 264 | RunningTasks: 1, |
| 265 | DesiredTasks: 3, |
| 266 | }, |
| 267 | }, |
| 268 | { |
| 269 | ID: "02_bar", |
| 270 | Spec: swarm.ServiceSpec{ |
| 271 | Annotations: swarm.Annotations{Name: "bar"}, |
| 272 | Mode: swarm.ServiceMode{ |
| 273 | Replicated: &swarm.ReplicatedService{}, |
| 274 | }, |
| 275 | }, |
| 276 | Endpoint: swarm.Endpoint{ |
| 277 | Ports: []swarm.PortConfig{ |
| 278 | { |
| 279 | PublishMode: "ingress", |
| 280 | PublishedPort: 80, |
| 281 | TargetPort: 8080, |
| 282 | Protocol: "tcp", |
| 283 | }, |
| 284 | }, |
| 285 | }, |
| 286 | ServiceStatus: &swarm.ServiceStatus{ |
| 287 | RunningTasks: 2, |
| 288 | DesiredTasks: 4, |
| 289 | }, |
| 290 | }, |
| 291 | }, |
| 292 | } |
| 293 | expectedJSONs := []map[string]any{ |
| 294 | {"ID": "02_bar", "Name": "bar", "Mode": "replicated", "Replicas": "2/4", "Image": "", "Ports": "*:80->8080/tcp"}, |
| 295 | {"ID": "01_baz", "Name": "baz", "Mode": "global", "Replicas": "1/3", "Image": "", "Ports": "*:80->8080/tcp"}, |
| 296 | } |
| 297 | |
| 298 | out := bytes.NewBufferString("") |
| 299 | err := ListFormatWrite(formatter.Context{Format: "{{json .}}", Output: out}, services) |
nothing calls this directly
no test coverage detected
searching dependent graphs…