Mercurial
comparison mrjunejune/test/snapshots/README.md @ 67:6626ec933933
[Seobeo] Separated out Client Server logic. Created test tools.
| author | June Park <parkjune1995@gmail.com> |
|---|---|
| date | Wed, 24 Dec 2025 09:15:55 -0800 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 66:a0f0ad5e42eb | 67:6626ec933933 |
|---|---|
| 1 # Test Snapshots | |
| 2 | |
| 3 This directory contains expected HTTP response snapshots for integration tests. | |
| 4 | |
| 5 ## How It Works | |
| 6 | |
| 7 Each test case generates a snapshot file based on its URL path: | |
| 8 | |
| 9 - `/` → `root.snapshot` | |
| 10 - `/index.html` → `index.html.snapshot` | |
| 11 - `/api/users` → `api_users.snapshot` | |
| 12 - `/path/to/resource` → `path_to_resource.snapshot` | |
| 13 | |
| 14 ## Workflow | |
| 15 | |
| 16 ### First time (no snapshots exist): | |
| 17 | |
| 18 1. Create snapshots: | |
| 19 ```bash | |
| 20 bazel run //mrjunejune:create_snapshots | |
| 21 ``` | |
| 22 | |
| 23 This will: | |
| 24 - Start the test server | |
| 25 - Make HTTP requests to all test paths | |
| 26 - Save responses to `mrjunejune/test/snapshots/` | |
| 27 | |
| 28 2. Verify tests pass: | |
| 29 ```bash | |
| 30 bazel test //mrjunejune:integration_test | |
| 31 ``` | |
| 32 | |
| 33 All tests should now pass since snapshots exist. | |
| 34 | |
| 35 ### Updating Snapshots | |
| 36 | |
| 37 When you change the server response format: | |
| 38 | |
| 39 1. Regenerate snapshots: | |
| 40 ```bash | |
| 41 bazel run //mrjunejune:create_snapshots | |
| 42 ``` | |
| 43 | |
| 44 2. Verify tests still pass: | |
| 45 ```bash | |
| 46 bazel test //mrjunejune:integration_test | |
| 47 ``` | |
| 48 | |
| 49 3. Commit the updated snapshot files | |
| 50 | |
| 51 ## Two Separate Commands | |
| 52 | |
| 53 - **`bazel run //mrjunejune:create_snapshots`** - Creates/updates snapshot files (uses seobeo snapshot creator library) | |
| 54 - **`bazel test //mrjunejune:integration_test`** - Verifies responses match snapshots | |
| 55 | |
| 56 This separation makes it clear when you're creating new snapshots vs. verifying against existing ones. | |
| 57 | |
| 58 ## Implementation Details | |
| 59 | |
| 60 The snapshot creation is implemented in the seobeo library: | |
| 61 - `seobeo/snapshot_creator.h` - Snapshot creation API | |
| 62 - `seobeo/snapshot_creator.c` - Implementation | |
| 63 - `mrjunejune/test/create_snapshots.c` - Binary that uses the library | |
| 64 | |
| 65 This makes snapshot creation reusable across different projects. | |
| 66 | |
| 67 ## Special Cases | |
| 68 | |
| 69 ### 200 OK Responses | |
| 70 Only 200 OK responses are verified against snapshots. This ensures successful responses remain consistent. | |
| 71 | |
| 72 ### Redirects (3xx status codes) | |
| 73 Redirect responses skip content comparison - only the status code is verified. | |
| 74 | |
| 75 ### Error Responses (4xx, 5xx) | |
| 76 Error status codes are verified but content comparison is skipped to allow for response format flexibility. |