Skip to content

Commit 31de91c

Browse files
committed
docs(tests): minor cleanup
1 parent 87a986b commit 31de91c

File tree

2 files changed

+43
-125
lines changed

2 files changed

+43
-125
lines changed

scripts/prune/README.md

Lines changed: 21 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -4,45 +4,33 @@
44

55
> Container image pruning script that supports both Docker Hub and GitHub Container Registry (GHCR).
66
7-
## Overview
7+
## Usage
88

9-
- Support both Docker Hub and GitHub Container Registry
10-
- Use a modular architecture with separate registry implementations
11-
- Provide multiple pruning strategies including a new "keep latest N images" option
12-
- Better error handling and logging
13-
14-
## Usage Examples
9+
```console
10+
usage: main.py [-h] --container CONTAINER
11+
[--registry {ghcr, dockerhub, all}]
12+
[--verbose] [--dry-run]
13+
(--prune-untagged-age DAYS | --prune-all-untagged | --keep-latest COUNT)
14+
```
1515

1616
### Environment Variables
1717

18-
To use the script, you need to set up environment variables for authentication. The script supports both Docker Hub and GitHub Container Registry.
18+
To use the script, you need to set up environment variables for authentication.
19+
The script supports both [Docker Hub](https://hub.docker.com) and [GitHub Container Registry](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry).
1920

20-
#### Docker Hub
21+
**Docker Hub variables:**
2122

2223
```bash
2324
export DOCKER_USERNAME=<your_docker_username>
2425
export DOCKER_PASSWORD=<your_docker_password_or_token>
2526
```
2627

27-
#### GitHub Container Registry
28+
**GitHub Container Registry variables:**
2829

2930
```bash
3031
export GHCR_TOKEN=<your_github_token>
3132
```
3233

33-
### Command Examples
34-
35-
```bash
36-
# Prune untagged images older than 7 days from both registries
37-
python main.py --container network-tools --registry all --prune-untagged-age 7 --verbose
38-
39-
# Keep only the latest 5 images in GHCR (delete everything else)
40-
python main.py --container network-tools --registry ghcr --keep-latest 5 --verbose
41-
42-
# Dry run: see what would be deleted from Docker Hub
43-
python main.py --container network-tools --registry dockerhub --prune-all-untagged --dry-run --verbose
44-
```
45-
4634
### CLI Options
4735

4836
- `--container`: Name of the container image (required)
@@ -56,81 +44,23 @@ python main.py --container network-tools --registry dockerhub --prune-all-untagg
5644
- `--prune-all-untagged`: Delete all untagged images
5745
- `--keep-latest COUNT`: Keep only the latest COUNT images
5846

59-
## Integration with GitHub Actions
47+
### Examples
6048

61-
The script is integrated into two GitHub Actions workflows:
62-
63-
### Production Usage (`cd.yml`)
49+
```bash
50+
# Prune untagged images older than 7 days from both registries
51+
python main.py --container network-tools --registry all --prune-untagged-age 7 --verbose
6452

65-
The script runs after successful image builds to clean up old images:
53+
# Keep only the latest 5 images in GHCR (delete everything else)
54+
python main.py --container network-tools --registry ghcr --keep-latest 5 --verbose
6655

67-
```yaml
68-
- name: Prune old images
69-
run: python scripts/prune/main.py --container ${{ env.IMAGE_NAME }} --registry all --keep-latest 25 --verbose
56+
# Dry run: see what would be deleted from Docker Hub
57+
python main.py --container network-tools --registry dockerhub --prune-all-untagged --dry-run --verbose
7058
```
7159

72-
### Automated Testing (`test-prune-script.yml`)
73-
74-
The test suite runs automatically whenever files in the prune directory are modified:
75-
76-
- ✅ Unit tests (20 comprehensive tests)
77-
- ✅ Integration tests (7 CLI tests)
78-
- ✅ Help interface validation
79-
- ✅ Dry-run functionality testing
80-
81-
This ensures that:
82-
83-
- All changes to the prune script are automatically tested
84-
- Old untagged images are cleaned up automatically in production
85-
- Storage usage is kept manageable
86-
- Both Docker Hub and GHCR are maintained consistently
87-
88-
## Error Handling
89-
90-
- Graceful handling of missing credentials
91-
- Registry-specific error reporting
92-
- Continues processing other registries if one fails
93-
- Detailed error messages in verbose mode
94-
9560
## Testing
9661

97-
The script includes a comprehensive test suite to ensure reliability and correctness. All tests are organized in the `tests/` directory.
98-
99-
### Test Structure
100-
101-
```plaintext
102-
tests/
103-
├── README.md # Testing documentation
104-
├── __init__.py # Package initialization
105-
├── test_prune.py # Comprehensive unit tests (20 tests)
106-
├── test_integration.py # Integration tests (7 tests)
107-
└── run_all_tests.py # Master test runner
108-
```
109-
110-
### Running Tests
111-
112-
**From the prune script root directory:**
113-
114-
```bash
115-
python test_runner.py # Master test runner
116-
```
117-
118-
**From the tests directory:**
119-
12062
```bash
121-
python tests/run_all_tests.py # Run all test suites
122-
python tests/test_prune.py # Unit tests only
123-
python tests/test_integration.py # Integration tests only
63+
python test_runner.py # Run all tests
12464
```
12565

126-
### Test Coverage
127-
128-
The test suite covers:
129-
130-
- ✅ All pruning strategies
131-
- ✅ Registry factory functionality
132-
- ✅ Error handling scenarios
133-
- ✅ CLI argument parsing
134-
- ✅ Dry-run functionality
135-
- ✅ Multi-registry support
136-
- ✅ Authentication handling
66+
> For comprehensive testing documentation, see [`tests/README.md`](tests/README.md).

scripts/prune/tests/README.md

Lines changed: 22 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,25 @@
1-
# Tests Directory
1+
# Tests
22

33
This directory contains comprehensive tests for the container image pruning script.
44

5-
## Test Files
5+
## Overview
6+
7+
The test suite provides comprehensive coverage of:
8+
9+
- ✅ All pruning strategies (age-based, all-untagged, keep-latest)
10+
- ✅ Multi-registry support (Docker Hub + GHCR)
11+
- ✅ Registry factory functionality
12+
- ✅ Error handling and edge cases
13+
- ✅ CLI argument parsing and validation
14+
- ✅ Dry-run functionality
15+
- ✅ Authentication handling
16+
- ✅ Modular architecture components
17+
18+
## Test Structure
619

720
### Core Test Suites
821

922
- **`test_prune.py`** - Comprehensive unit tests covering all components (20 tests)
10-
1123
- ImageVersion class functionality
1224
- All pruning strategies
1325
- Registry factory
@@ -27,7 +39,7 @@ This directory contains comprehensive tests for the container image pruning scri
2739

2840
## Running Tests
2941

30-
### From the prune script root directory:
42+
### From the prune script root directory
3143

3244
```bash
3345
# Run all tests using the master test runner
@@ -37,7 +49,7 @@ python test_runner.py
3749
python tests/run_all_tests.py
3850
```
3951

40-
### From the tests directory:
52+
### From the tests directory
4153

4254
```bash
4355
# Run individual test files
@@ -48,45 +60,21 @@ python test_integration.py # Integration tests
4860
python run_all_tests.py
4961
```
5062

51-
## Test Coverage
52-
53-
The test suite provides comprehensive coverage of:
54-
55-
- ✅ All pruning strategies (age-based, all-untagged, keep-latest)
56-
- ✅ Multi-registry support (Docker Hub + GHCR)
57-
- ✅ Registry factory functionality
58-
- ✅ Error handling and edge cases
59-
- ✅ CLI argument parsing and validation
60-
- ✅ Dry-run functionality
61-
- ✅ Authentication handling
62-
- ✅ Modular architecture components
63-
64-
## Test Results
65-
66-
**Current Status:** All tests passing ✅
67-
68-
- 20/20 unit tests passed
69-
- 7/7 integration tests passed
70-
- 5/5 core functionality tests passed
71-
- **Total: 32/32 tests passed**
72-
7363
## Adding New Tests
7464

7565
When adding new functionality to the prune script:
7666

77-
1. Add unit tests to `test_prune.py` for new components
78-
2. Add integration tests to `test_integration.py` for CLI changes
79-
3. Update `validate_tests.py` for core functionality changes
67+
1. Add unit tests to [`test_prune.py`](test_prune.py) for new components
68+
2. Add integration tests to [`test_integration.py`](test_integration.py) for CLI changes
69+
3. Run [`run_all_tests.py`](run_all_tests.py) to validate all functionality works together
8070
4. Run the full test suite to ensure no regressions
8171

82-
## Test Dependencies
72+
## Dependencies
8373

84-
Tests use only Python standard library modules:
74+
Tests use only Python standard library modules (no external dependencies):
8575

8676
- `unittest` - Main testing framework
8777
- `unittest.mock` - Mocking for isolated testing
8878
- `subprocess` - For CLI integration tests
8979
- `datetime` - For time-based testing
9080
- `pathlib` - For file path handling
91-
92-
No external dependencies required for testing.

0 commit comments

Comments
 (0)