@Test
    public void test_snapshots() throws IOException {
        SecretStoreMock secretStore = (SecretStoreMock) tester.container().components()
                                                              .getComponent(SecretStoreMock.class.getName());
        KeyPair keyPair = KeyUtils.generateX25519KeyPair();
        secretStore.add(new Secret(Key.fromString("snapshot/sealingPrivateKey"),
                                   KeyUtils.toPem(keyPair.getPrivate(), KeyFormat.PKCS8).getBytes(),
                                   SecretVersionId.of("1")));

        // Trigger creation of snapshots
        String createSnapshotResponse = tester.container()
                                              .handleRequest(new Request("http://localhost:8080/nodes/v2/snapshot/host4.yahoo.com", new byte[0], Request.Method.POST))
                                              .getBodyAsString();
        String id0 = SlimeUtils.jsonToSlime(createSnapshotResponse).get().field("id").asString();
        assertEquals("{\"id\":\"" + id0 + "\",\"message\":\"Triggered a new snapshot of host4.yahoo.com: " + id0 + "\"}",
                     createSnapshotResponse);
        tester.assertResponseContains(new Request("http://localhost:8080/nodes/v2/snapshot/host4.yahoo.com",
                                                  new byte[0], Request.Method.POST),
                                      "{\"error-code\":\"BAD_REQUEST\",\"message\":\"Cannot trigger new snapshot: Node host4.yahoo.com is busy with snapshot");
        tester.assertResponseContains(new Request("http://localhost:8080/nodes/v2/snapshot/host2.yahoo.com",
                                                  new byte[0], Request.Method.POST),
                                      "\"message\":\"Triggered a new snapshot of host2.yahoo.com:");

        // List snapshots
        assertFile(new Request("http://localhost:8080/nodes/v2/snapshot"), "snapshot/list.json");
        assertFile(new Request("http://localhost:8080/nodes/v2/snapshot/host4.yahoo.com"), "snapshot/list-host.json");
        assertFile(new Request("http://localhost:8080/nodes/v2/snapshot/host4.yahoo.com/" + id0), "snapshot/single.json");

        // Update snapshot state
        tester.assertResponse(new Request("http://localhost:8080/nodes/v2/snapshot/host4.yahoo.com/" + id0,
                                          """
                                                  {"state": "created"}
                                                  """,
                                          Request.Method.PATCH),
                              "{\"message\":\"Updated snapshot '" + id0 + "' for node host4.yahoo.com\"}");

        // List snapshots
        assertFile(new Request("http://localhost:8080/nodes/v2/snapshot/host4.yahoo.com"), "snapshot/list-host-updated.json");

        // Get node
        tester.assertFile(new Request("http://localhost:8080/nodes/v2/node/host4.yahoo.com"), "snapshot/node4.json");

        // Retrieve encryption key
        String receiverPublicKey = KeyUtils.toBase64EncodedX25519PublicKey((XECPublicKey) KeyUtils.generateX25519KeyPair().getPublic());
        tester.assertResponseContains(new Request("http://localhost:8080/nodes/v2/snapshot/host4.yahoo.com/" + id0 + "/key",
                                                  "{\"sealingKey\":\"" + receiverPublicKey + "\"}", Request.Method.POST),
                                      "{\"sealedSharedKey\"");

        // Trigger another snapshot
        createSnapshotResponse = tester.container()
                                       .handleRequest(new Request("http://localhost:8080/nodes/v2/snapshot/host4.yahoo.com", new byte[0], Request.Method.POST))
                                       .getBodyAsString();
        String id1 = SlimeUtils.jsonToSlime(createSnapshotResponse).get().field("id").asString();

        // Cannot trigger restore while busy with a different snapshot
        tester.assertResponse(new Request("http://localhost:8080/nodes/v2/snapshot/host4.yahoo.com/" + id0 + "/restore",
                                          new byte[0],
                                          Request.Method.POST),
                              400,
                              "{\"error-code\":\"BAD_REQUEST\",\"message\":\"Cannot restore snapshot: Node host4.yahoo.com is busy with snapshot " + id1 + " in creating state\"}");

        // Cannot change state of a non-active snapshot
        tester.assertResponse(new Request("http://localhost:8080/nodes/v2/snapshot/host4.yahoo.com/" + id0,
                                          """
                                                  {"state": "restored"}
                                                  """,
                                          Request.Method.PATCH),
                              400,
                              "{\"error-code\":\"BAD_REQUEST\",\"message\":\"Cannot move snapshot " + id0 + " to restored: Node host4.yahoo.com is not working on this snapshot\"}");

        // Snapshot completes
        tester.assertResponse(new Request("http://localhost:8080/nodes/v2/snapshot/host4.yahoo.com/" + id1,
                                          """
                                                  {"state": "created"}
                                                  """,
                                          Request.Method.PATCH),
                              "{\"message\":\"Updated snapshot '" + id1 + "' for node host4.yahoo.com\"}");

        // Start restore of snapshot
        tester.assertResponse(new Request("http://localhost:8080/nodes/v2/snapshot/host4.yahoo.com/" + id1 + "/restore",
                                          new byte[0],
                                          Request.Method.POST),
                              200,
                              "{\"message\":\"Triggered restore of snapshot '" + id1 + "' to host4.yahoo.com\"}");

        // Forget about snapshot
        assertResponse(new Request("http://localhost:8080/nodes/v2/snapshot/host4.yahoo.com/" + id0, new byte[0], Request.Method.DELETE),
                       "{\"message\":\"Removed snapshot '" + id0 + "' belonging to host4.yahoo.com\"}");

        // Forgetting about active snapshot fails
        tester.assertResponse(new Request("http://localhost:8080/nodes/v2/snapshot/host4.yahoo.com/" + id1, new byte[0], Request.Method.DELETE),
                              400,
                              "{\"error-code\":\"BAD_REQUEST\",\"message\":\"Cannot remove snapshot " + id1 + ": Node host4.yahoo.com is working on this snapshot\"}");
        // ..., but succeeds with force
        tester.assertResponse(new Request("http://localhost:8080/nodes/v2/snapshot/host4.yahoo.com/" + id1 + "?force=true", new byte[0], Request.Method.DELETE),
                              200,
                              "{\"message\":\"Removed snapshot '" + id1 + "' belonging to host4.yahoo.com\"}");
    }
This test gives examples of the node requests that can be made to nodes/v2
node-repository/src/test/java/com/yahoo/vespa/hosted/provision/restapi/NodesV2ApiTest.java