From a615baa78ab437c5ae4d401777f2fd1fdc857841 Mon Sep 17 00:00:00 2001
From: Heikki Linnakangas <heikki@neon.tech>
Date: Wed, 29 Jan 2025 20:34:10 +0200
Subject: [PATCH] tests: test_pgdata_import_smoke requires the 'testing' cargo
 feature

It took me ages to figure out why it was failing on my laptop. What I
saw was that when the test makes the 'import_pgdata' in the
pageserver, the pageserver actually performs a regular 'bootstrap'
timeline creation by running initdb, with no importing. It boiled down
to the json request that the test uses:

```
        {
            "new_timeline_id": str(timeline_id),
            "import_pgdata": {
                "idempotency_key": str(idempotency),
                "location": {"LocalFs": {"path": str(importbucket.absolute())}},
            },
        },
```

and how serde deserializes into rust structs. The 'LocalFs' enum
variant in `models.rs` is gated on the 'testing' cargo feature. On a
non-testing build, that got deserialized into the default Bootstrap
enum variant, as a valid TimelineCreateRequestModeImportPgdata variant
could not be formed.

PS. IMHO we should get rid of the testing feature, compile in all the
functionality, and have a runtime flag to disable anything
dangeorous. With that, you would've gotten a nice "feature only
enabled in testing mode" error in this case, or the test would've
simply worked. But that's another story.
---
 test_runner/regress/test_import_pgdata.py | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/test_runner/regress/test_import_pgdata.py b/test_runner/regress/test_import_pgdata.py
index 182f715b0ef4..086d4b67c9e3 100644
--- a/test_runner/regress/test_import_pgdata.py
+++ b/test_runner/regress/test_import_pgdata.py
@@ -59,6 +59,9 @@ def handler(request: Request) -> Response:
     neon_env_builder.enable_pageserver_remote_storage(RemoteStorageKind.LOCAL_FS)
     env = neon_env_builder.init_start()
 
+    # The test needs LocalFs support, which is only built in testing mode.
+    env.pageserver.is_testing_enabled_or_skip()
+
     env.pageserver.patch_config_toml_nonrecursive(
         {
             "import_pgdata_upcall_api": f"http://{cplane_mgmt_api_server.host}:{cplane_mgmt_api_server.port}/path/to/mgmt/api"