docker-wrapper 0.11.1

A Docker CLI wrapper for Rust
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
//! Integration tests for Docker info command.
//!
//! These tests validate the info command functionality against a real Docker daemon.
//! They test the command construction, execution, and output parsing.

use docker_wrapper::{ensure_docker, InfoCommand};

/// Helper to check if Docker is available for testing
async fn setup_docker() -> Result<(), Box<dyn std::error::Error>> {
    ensure_docker().await?;
    Ok(())
}

#[tokio::test]
async fn test_info_prerequisites_validation() -> Result<(), Box<dyn std::error::Error>> {
    setup_docker().await?;
    Ok(())
}

#[tokio::test]
async fn test_info_basic_command() -> Result<(), Box<dyn std::error::Error>> {
    setup_docker().await?;

    let command = InfoCommand::new();
    let args = command.build_command_args();

    // Verify the basic command structure

    assert_eq!(args[0], "info");
    // Default info should just have the command name
    assert_eq!(args, vec!["info"]);

    // Test the command builds without errors
    assert!(!args.is_empty());
    Ok(())
}

#[tokio::test]
async fn test_info_command_builder() -> Result<(), Box<dyn std::error::Error>> {
    setup_docker().await?;

    let command = InfoCommand::new().format("json");

    let args = command.build_command_args();

    // Verify format option is present

    assert_eq!(args[0], "info");
    assert!(args.contains(&"--format".to_string()));
    assert!(args.contains(&"json".to_string()));
    Ok(())
}

#[tokio::test]
async fn test_info_format_variations() -> Result<(), Box<dyn std::error::Error>> {
    setup_docker().await?;

    let formats = vec![
        "json",
        "table",
        "{{.ServerVersion}}",
        "{{.Name}}",
        "{{.DriverStatus}}",
    ];

    for format in formats {
        let command = InfoCommand::new().format(format);
        let args = command.build_command_args();
        assert_eq!(args[0], "info");
        assert!(args.contains(&"--format".to_string()));
        assert!(args.contains(&format.to_string()));
    }
    Ok(())
}

#[tokio::test]
async fn test_info_json_format() -> Result<(), Box<dyn std::error::Error>> {
    setup_docker().await?;

    let command = InfoCommand::new().format("json");
    let args = command.build_command_args();

    // Verify JSON format
    assert!(args.contains(&"--format".to_string()));
    assert!(args.contains(&"json".to_string()));
    Ok(())
}

#[tokio::test]
async fn test_info_table_format() -> Result<(), Box<dyn std::error::Error>> {
    setup_docker().await?;

    let command = InfoCommand::new().format("table");
    let args = command.build_command_args();

    // Verify table format
    assert!(args.contains(&"--format".to_string()));
    assert!(args.contains(&"table".to_string()));
    Ok(())
}

#[tokio::test]
async fn test_info_custom_go_template() -> Result<(), Box<dyn std::error::Error>> {
    setup_docker().await?;

    let template = "Server Version: {{.ServerVersion}}, Storage Driver: {{.Driver}}";
    let command = InfoCommand::new().format(template);
    let args = command.build_command_args();

    // Verify custom template
    assert!(args.contains(&"--format".to_string()));
    assert!(args.contains(&template.to_string()));
    Ok(())
}

#[tokio::test]
async fn test_info_command_name() -> Result<(), Box<dyn std::error::Error>> {
    setup_docker().await?;

    let command = InfoCommand::new();
    let args = command.build_command_args();
    assert_eq!(args[0], "info");
    Ok(())
}

#[tokio::test]
async fn test_info_command_display() -> Result<(), Box<dyn std::error::Error>> {
    setup_docker().await?;

    let command = InfoCommand::new().format("json");

    let args = command.build_command_args();
    assert!(!args.is_empty());
    assert_eq!(args[0], "info");
    assert!(args.contains(&"--format".to_string()));
    assert!(args.contains(&"json".to_string()));
    Ok(())
}

#[tokio::test]
async fn test_info_default_format() -> Result<(), Box<dyn std::error::Error>> {
    setup_docker().await?;

    let command = InfoCommand::new();
    let args = command.build_command_args();

    // Default should not include format flag

    assert_eq!(args[0], "info");
    assert_eq!(args, vec!["info"]);
    Ok(())
}

#[tokio::test]
async fn test_info_format_parsing_concept() -> Result<(), Box<dyn std::error::Error>> {
    setup_docker().await?;

    // Test that different format commands produce expected arguments
    let json_command = InfoCommand::new().format("json");
    let table_command = InfoCommand::new().format("table");

    let json_args = json_command.build_command_args();
    let table_args = table_command.build_command_args();

    // Verify format arguments are correctly set
    assert!(json_args.contains(&"--format".to_string()));
    assert!(json_args.contains(&"json".to_string()));
    assert!(table_args.contains(&"--format".to_string()));
    assert!(table_args.contains(&"table".to_string()));
    Ok(())
}

#[tokio::test]
async fn test_info_command_order() -> Result<(), Box<dyn std::error::Error>> {
    setup_docker().await?;

    let command = InfoCommand::new().format("table");

    let args = command.build_command_args();

    // Verify command structure

    assert_eq!(args[0], "info");
    assert!(args.contains(&"--format".to_string()));
    assert!(args.contains(&"table".to_string()));
    Ok(())
}

#[tokio::test]
async fn test_info_empty_format_handling() -> Result<(), Box<dyn std::error::Error>> {
    setup_docker().await?;

    // Test with empty format (should behave like default)
    let command = InfoCommand::new().format("");
    let args = command.build_command_args();

    // Should still produce valid command
    assert_eq!(args[0], "info");
    // Empty format still gets passed as a flag
    assert_eq!(args, vec!["info", "--format", ""]);
    Ok(())
}

#[tokio::test]
async fn test_info_complex_go_templates() -> Result<(), Box<dyn std::error::Error>> {
    setup_docker().await?;

    let complex_templates = vec![
        "{{.ServerVersion}}",
        "{{.Name}}",
        "{{json .}}",
        "Server: {{.ServerVersion}}\nDriver: {{.Driver}}",
        "{{range .Plugins.Storage}}{{.}}\n{{end}}",
        "{{.NCPU}} CPUs, {{.MemTotal}} bytes memory",
    ];

    for template in complex_templates {
        let command = InfoCommand::new().format(template);
        let args = command.build_command_args();
        assert_eq!(args[0], "info");
        assert!(args.contains(&"--format".to_string()));
        assert!(args.contains(&template.to_string()));
    }
    Ok(())
}

#[tokio::test]
async fn test_info_system_information_templates() -> Result<(), Box<dyn std::error::Error>> {
    setup_docker().await?;

    let system_templates = vec![
        "{{.Architecture}}",
        "{{.OSType}}",
        "{{.KernelVersion}}",
        "{{.OperatingSystem}}",
        "{{.DockerRootDir}}",
        "{{.SystemTime}}",
    ];

    for template in system_templates {
        let command = InfoCommand::new().format(template);
        let args = command.build_command_args();
        assert_eq!(args[0], "info");
        assert!(args.contains(&"--format".to_string()));
        assert!(args.contains(&template.to_string()));
    }
    Ok(())
}

#[tokio::test]
async fn test_info_container_runtime_templates() -> Result<(), Box<dyn std::error::Error>> {
    setup_docker().await?;

    let runtime_templates = vec![
        "{{.ContainersRunning}}",
        "{{.ContainersPaused}}",
        "{{.ContainersStopped}}",
        "{{.Images}}",
        "{{.Driver}}",
        "{{.LoggingDriver}}",
        "{{.CgroupDriver}}",
    ];

    for template in runtime_templates {
        let command = InfoCommand::new().format(template);
        let args = command.build_command_args();
        assert_eq!(args[0], "info");
        assert!(args.contains(&"--format".to_string()));
        assert!(args.contains(&template.to_string()));
    }
    Ok(())
}

#[tokio::test]
async fn test_info_validation() -> Result<(), Box<dyn std::error::Error>> {
    setup_docker().await?;

    // Test command validation
    let command = InfoCommand::new().format("json");

    // Test command name
    let args = command.build_command_args();
    assert_eq!(args[0], "info");

    // Test build args format
    let args = command.build_command_args();
    assert!(!args.is_empty());
    assert!(args.contains(&"--format".to_string()));
    assert!(args.contains(&"json".to_string()));
    Ok(())
}

#[tokio::test]
async fn test_info_builder_pattern() -> Result<(), Box<dyn std::error::Error>> {
    setup_docker().await?;

    // Test fluent builder pattern
    let command = InfoCommand::new().format("json");

    let args = command.build_command_args();
    assert_eq!(args[0], "info");
    assert!(args.contains(&"--format".to_string()));
    assert!(args.contains(&"json".to_string()));

    // Test that builder methods can be chained
    let chained_command = InfoCommand::new()
        .format("table")
        .format("{{.ServerVersion}}"); // Last format wins

    let chained_args = chained_command.build_command_args();
    assert!(chained_args.contains(&"--format".to_string()));
    assert!(chained_args.contains(&"{{.ServerVersion}}".to_string()));
    Ok(())
}

#[tokio::test]
async fn test_info_format_edge_cases() -> Result<(), Box<dyn std::error::Error>> {
    setup_docker().await?;

    // Test with format containing spaces and special characters
    let edge_case_formats = vec![
        "table {{.ServerVersion}}",
        "{{.Name}} - {{.ServerVersion}}",
        "json",
        "{{range .Plugins.Network}}{{.}}\n{{end}}",
        "CPU: {{.NCPU}}, Memory: {{.MemTotal}}",
    ];

    for format in edge_case_formats {
        let command = InfoCommand::new().format(format);
        let args = command.build_command_args();
        assert_eq!(args[0], "info");
        assert!(args.contains(&"--format".to_string()));
        // Format should be properly included
        assert!(args.contains(&format.to_string()));
    }
    Ok(())
}

#[tokio::test]
async fn test_info_output_parsing_concept() -> Result<(), Box<dyn std::error::Error>> {
    setup_docker().await?;

    // Test the command structure that would be used for output parsing
    let json_command = InfoCommand::new().format("json");
    let table_command = InfoCommand::new().format("table");
    let default_command = InfoCommand::new();

    // Verify different formats produce different commands
    assert!(json_command
        .build_command_args()
        .contains(&"--format".to_string()));
    assert!(json_command
        .build_command_args()
        .contains(&"json".to_string()));
    assert!(table_command
        .build_command_args()
        .contains(&"--format".to_string()));
    assert!(table_command
        .build_command_args()
        .contains(&"table".to_string()));
    assert_eq!(default_command.build_command_args(), vec!["info"]);

    // All should be valid info commands
    Ok(())
}

#[tokio::test]
async fn test_info_security_context_templates() -> Result<(), Box<dyn std::error::Error>> {
    setup_docker().await?;

    let security_templates = vec![
        "{{.SecurityOptions}}",
        "{{range .SecurityOptions}}{{.}}\n{{end}}",
        "{{.Warnings}}",
        "{{range .Warnings}}Warning: {{.}}\n{{end}}",
    ];

    for template in security_templates {
        let command = InfoCommand::new().format(template);
        let args = command.build_command_args();
        assert_eq!(args[0], "info");
        assert!(args.contains(&"--format".to_string()));
        assert!(args.contains(&template.to_string()));
    }
    Ok(())
}

#[tokio::test]
async fn test_info_storage_templates() -> Result<(), Box<dyn std::error::Error>> {
    setup_docker().await?;

    let storage_templates = vec![
        "{{.DriverStatus}}",
        "{{range .DriverStatus}}{{index . 0}}: {{index . 1}}\n{{end}}",
        "{{.DockerRootDir}}",
        "{{.Driver}}",
    ];

    for template in storage_templates {
        let command = InfoCommand::new().format(template);
        let args = command.build_command_args();
        assert_eq!(args[0], "info");
        assert!(args.contains(&"--format".to_string()));
        assert!(args.contains(&template.to_string()));
    }
    Ok(())
}