@@ -80,3 +80,89 @@ def test_audit_returns_empty(docker_module):
8080 assert isinstance (result , AuditResult )
8181 assert result .status == "pass"
8282 assert result .findings == []
83+
84+
85+ def test_parse_reclaimed_space_gb ():
86+ """Test parsing GB from docker prune output."""
87+ output = "Total reclaimed space: 1.5GB"
88+ result = DockerModule ._parse_reclaimed_space (output )
89+ assert result == 1610612736 # 1.5 * 1024^3
90+
91+
92+ def test_parse_reclaimed_space_mb ():
93+ """Test parsing MB from docker prune output."""
94+ output = "Total reclaimed space: 500MB"
95+ result = DockerModule ._parse_reclaimed_space (output )
96+ assert result == 524288000 # 500 * 1024^2
97+
98+
99+ def test_parse_reclaimed_space_kb ():
100+ """Test parsing KB from docker prune output."""
101+ output = "Total reclaimed space: 1024KB"
102+ result = DockerModule ._parse_reclaimed_space (output )
103+ assert result == 1048576 # 1024 * 1024
104+
105+
106+ def test_parse_reclaimed_space_bytes ():
107+ """Test parsing bytes from docker prune output."""
108+ output = "Total reclaimed space: 100B"
109+ result = DockerModule ._parse_reclaimed_space (output )
110+ assert result == 100
111+
112+
113+ def test_parse_reclaimed_space_empty ():
114+ """Test parsing empty string returns 0."""
115+ result = DockerModule ._parse_reclaimed_space ("" )
116+ assert result == 0
117+
118+
119+ def test_parse_reclaimed_space_no_match ():
120+ """Test parsing random text returns 0."""
121+ output = "Some random docker output without space info"
122+ result = DockerModule ._parse_reclaimed_space (output )
123+ assert result == 0
124+
125+
126+ def test_parse_reclaimed_space_with_surrounding_text ():
127+ """Test parsing with other text before/after the reclaimed line."""
128+ output = """Deleted Images:
129+ untagged: sha256:abc123
130+ untagged: sha256:def456
131+
132+ Total reclaimed space: 2.5GB
133+
134+ Some other output here"""
135+ result = DockerModule ._parse_reclaimed_space (output )
136+ assert result == 2684354560 # 2.5 * 1024^3
137+
138+
139+ def test_scan_docker_stopped_containers ():
140+ """Test scan reports stopped containers when enabled."""
141+ docker_module = DockerModule (remove_stopped_containers = True )
142+ with (
143+ patch .object (docker_module , "_is_docker_running" , return_value = True ),
144+ patch .object (docker_module , "_get_dangling_images" , return_value = []),
145+ patch .object (docker_module , "_get_unused_volumes" , return_value = []),
146+ patch .object (docker_module , "_get_stopped_containers" , return_value = ["c1" , "c2" ]),
147+ ):
148+ result = docker_module .scan ()
149+
150+ assert isinstance (result , ScanResult )
151+ assert len (result .items ) == 1
152+ assert "2 stopped containers" in result .items [0 ]
153+
154+
155+ def test_clean_all_flags_disabled ():
156+ """Test clean does nothing when all flags are False."""
157+ docker_module = DockerModule (
158+ remove_dangling_images = False ,
159+ remove_unused_volumes = False ,
160+ remove_stopped_containers = False ,
161+ )
162+ with patch .object (docker_module , "_is_docker_running" , return_value = True ):
163+ result = docker_module .clean ()
164+
165+ assert isinstance (result , CleanResult )
166+ assert result .items_cleaned == []
167+ assert result .bytes_reclaimed == 0
168+ assert result .errors == []
0 commit comments