googleapis / google-cloud-cpp

C++ Client Libraries for Google Cloud Services
https://cloud.google.com/
Apache License 2.0
545 stars 370 forks source link

We should run generated quickstarts #7936

Closed dbolduc closed 2 years ago

dbolduc commented 2 years ago

We compile generated quickstarts, but we never run them. https://github.com/googleapis/google-cloud-cpp/blob/ac535f71e6c1baa3a81caa1fb565d5d0e29e1133/ci/etc/quickstart-config.sh#L25-L32

It will also take some effort to figure out what arguments should be used, and whether any setup is necessary to run a given quickstart.


Cleanup

After #8254 the following libraries will need work:

Cannot run in our CI Builds

Requires Custom Resources

Requires Permissions unavailable to a Service Account

Requires X-User-Project (#8245)

Hangs

Fails

coryan commented 2 years ago

Proposal

I will change the generator to create test targets for the quickstart programs. These test targets will:

Overview

A build target for CMake may look like this:

include(CTest)
if (BUILD_TESTING)
    add_executable(filestore_quickstart "quickstart/quickstart.cc")
    target_link_libraries(filestore_quickstart
                          PRIVATE google-cloud-cpp::experimental-filestore)
    google_cloud_cpp_add_common_options(filestore_quickstart)
    add_test(
        NAME filestore_quickstart
        COMMAND cmake -P "${PROJECT_SOURCE_DIR}/cmake/quickstart-runner.cmake"
                $<TARGET_FILE:filestore_quickstart> GOOGLE_CLOUD_PROJECT)
    set_tests_properties(filestore_quickstart
                         PROPERTIES LABELS "integration-test;quickstart")
endif ()

For Bazel it may look like this:

sh_test(
    name = "quickstart_test",
    srcs = ["//bazel:quickstart-runner.sh"],
    args = [
        "filestore",
        "GOOGLE_CLOUD_PROJECT",
    ],
    data = ["//google/cloud/filestore/quickstart:quickstart"],
    tags = [
        "integration-test",
        "quickstart",
    ],
)

The generator will include this code in the scaffold, we only need to edit the names of the environment variables.

Details

I expect I will use the generator to update most libraries, I will run the generator with the --scaffold option, then use a loop to revert the changes to all files except for ${library}/{CMakeLists.txt,BUILD.bazel,quickstart/BUILD.bazel}. Then I will revert any unwanted changes. I anticipate I will need to enable a number of services and update our project configuration before sending the PR.

Differences from the current quickstart tests

We run the quickstart programs for different reasons:

I propose that we only solve the first problem with this PR. We have existing builds to verify the quickstart programs compile when the library is installed, e.g., https://github.com/googleapis/google-cloud-cpp/blob/62cb8319e40f97858bd821169ec36d31a66445bb/ci/verify_quickstart/CMakeLists.txt#L20.

I do not think we need to verify the quickstart programs run when compiled as part of the project and also run when compiled as standalone programs.

Future Work

We need to refactor the builds to use a similar scheme for hand-crafted libraries.

coryan commented 2 years ago

This is now done. We could improve some of the quickstarts tests (but the quickstarts themselves are Okay) by having a test organization and test folders, but they are good enough as-is.