void cacheAcrossContexts()

in plugins/vault/src/integrationTest/java/co/elastic/gradle/vault/VaultPluginIT.java [133:208]


    void cacheAcrossContexts() {
        final var host = vaultContainer.getHost();
        final var firstMappedPort = vaultContainer.getFirstMappedPort();
        helper.settings(String.format("""
                           import %s
                           include("subproject")
                           plugins {
                               id("co.elastic.vault")
                           }
                           configure<VaultExtension> {
                              engineVersion.set(2)
                              retries.set(2)
                              retryDelayMillis.set(1000)
                              address.set("http://%s:%s/")
                              auth {
                                tokenFile(file("no/such/token"))
                                roleAndSecretEnv("JUST_A", "LIE")
                                roleAndSecretEnv()
                                ghTokenEnv("SOME_GH_TOKEN")
                                ghTokenEnv()
                                ghTokenFile(file("theres/no/such/file"))
                                tokenEnv("MY_ENV_TOKEN")
                              }
                           }
                           val vault = the<VaultExtension>()
                           logger.lifecycle("settings: db_password is {}", vault.readAndCacheSecret("secret/testing2").get()["db_password"])
                        """,
                VaultExtension.class.getName(), host, firstMappedPort)
        );

        helper.buildScript("""
                plugins {
                    id("co.elastic.vault")
                }
                vault {
                    address.set("http://127.0.0.1:8200/")
                    auth {
                     tokenEnv()
                    }
                }
                logger.lifecycle("root project: db_password is {}", vault.readAndCacheSecret("secret/testing2").get()["db_password"])
                """
        );
        helper.buildScript("subproject", """
                 plugins {
                    id("co.elastic.vault")
                }
                vault {
                    address.set("http://127.0.0.1:8200/")
                    auth {
                     tokenEnv()
                    }
                }
                logger.lifecycle("subproject: db_password is {}", vault.readAndCacheSecret("secret/testing2").get()["db_password"])
                """
        );

        final BuildResult result = gradleRunner
                .withEnvironment(Collections.singletonMap("MY_ENV_TOKEN", "my-root-token"))
                .withArguments("--warning-mode", "fail", "-s", "help")
                .build();
        assertContains(result.getOutput(), "settings: db_password is dbpassword1");
        assertContains(result.getOutput(), "root project: db_password is dbpassword1");
        assertContains(result.getOutput(), "subproject: db_password is dbpassword1");

        vaultContainer.stop();

        final BuildResult secondResult = gradleRunner
                .withEnvironment(Collections.singletonMap("MY_ENV_TOKEN", "my-root-token"))
                .withArguments("--warning-mode", "fail", "-s", "help")
                .build();
        assertContains(result.getOutput(), "settings: db_password is dbpassword1");
        assertContains(result.getOutput(), "root project: db_password is dbpassword1");
        assertContains(result.getOutput(), "subproject: db_password is dbpassword1");
        assertCacheLocationDoesNotExists("subproject/.gradle");
    }