A compose file's edit replaces its build edges: the renamed image keeps * no edge (nor node), the new one has its edge. `legacy`: through the * full-load route, else the closure-repair route. Returns "old=N new=M" * after the edit, or NULL; *route: the route taken. */
| 3967 | * full-load route, else the closure-repair route. Returns "old=N new=M" |
| 3968 | * after the edit, or NULL; *route: the route taken. */ |
| 3969 | static char *incremental_compose_edit(bool legacy, cbm_incremental_route_t *route) { |
| 3970 | char tmp[256]; |
| 3971 | snprintf(tmp, sizeof(tmp), "/tmp/cbm_composeedit_XXXXXX"); |
| 3972 | if (!cbm_mkdtemp(tmp)) { |
| 3973 | return NULL; |
| 3974 | } |
| 3975 | write_temp_file(tmp, "src/web/Dockerfile", "FROM nginx:1.27\n"); |
| 3976 | write_temp_file(tmp, "src/api/Dockerfile", "FROM golang:1.22\n"); |
| 3977 | write_temp_file(tmp, "compose.yaml", |
| 3978 | "services:\n web:\n image: acme/web-old\n build: ./src/web\n" |
| 3979 | " api:\n image: acme/api\n build: ./src/api\n"); |
| 3980 | char db_path[512]; |
| 3981 | snprintf(db_path, sizeof(db_path), "%s/composeedit.db", tmp); |
| 3982 | static const char old_img[] = "SELECT COUNT(*) FROM nodes WHERE label='Image' AND " |
| 3983 | "name='acme/web-old'"; |
| 3984 | static const char new_edge[] = |
| 3985 | "SELECT COUNT(*) FROM edges e JOIN nodes s ON s.id=e.source_id WHERE e.type='DEPENDS_ON' " |
| 3986 | "AND s.name='acme/web-new'"; |
| 3987 | if (k8s_inc_index(tmp, db_path) != 0 || k8s_inc_count(db_path, old_img) != 1) { |
| 3988 | th_rmtree(tmp); |
| 3989 | return NULL; |
| 3990 | } |
| 3991 | write_temp_file(tmp, "compose.yaml", |
| 3992 | "services:\n web:\n image: acme/web-new\n build: ./src/web\n" |
| 3993 | " api:\n image: acme/api\n build: ./src/api\n"); |
| 3994 | #if defined(CBM_INCREMENTAL_TEST_API) && CBM_INCREMENTAL_TEST_API |
| 3995 | if (legacy) { |
| 3996 | cbm_pipeline_incremental_test_force_legacy_partial_once(); |
| 3997 | } |
| 3998 | #else |
| 3999 | (void)legacy; |
| 4000 | #endif |
| 4001 | char *out = NULL; |
| 4002 | if (k8s_inc_index(tmp, db_path) == 0) { |
| 4003 | char buf[64]; |
| 4004 | snprintf(buf, sizeof(buf), "old=%d new=%d", k8s_inc_count(db_path, old_img), |
| 4005 | k8s_inc_count(db_path, new_edge)); |
| 4006 | out = strdup(buf); |
| 4007 | } |
| 4008 | *route = cbm_pipeline_incremental_test_last_route(); |
| 4009 | th_rmtree(tmp); |
| 4010 | return out; |
| 4011 | } |
| 4012 | |
| 4013 | TEST(incremental_compose_edit_replaces_build_edges) { |
| 4014 | cbm_incremental_route_t route = CBM_INCREMENTAL_ROUTE_NONE; |
no test coverage detected