Skip to content

Commit

Permalink
Add details for local and integration testing (#49)
Browse files Browse the repository at this point in the history
* tease apart the example, testing, and CI steps

* Address code review

* add Python venv sourcing

* tweak wording
  • Loading branch information
guineveresaenger authored Nov 17, 2021
1 parent 959ffe7 commit f169979
Showing 1 changed file with 53 additions and 11 deletions.
64 changes: 53 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,17 +189,16 @@ The following instructions all pertain to `provider/resources.go`, in the sectio

**Note:** If you make revisions to code in `resources.go`, you must re-run the `make tfgen` target to regenerate the schema. Pulumi providers use Go 1.16, which does not have the ability to directly embed text files. The `make tfgen` target will take the file `schema.json` and serialize it to a byte array so that it can be included in the build output. (Go 1.17 will remove the need for this step.)

## Sample Program and End-to-end Testing
## Sample Program

In this section, we will create a Pulumi program in TypeScript that utilizes the provider we created to ensure everything is working properly.

1. Create an account with the provider's service and generate any necessary credentials, e.g. API keys:
* Email: [email protected]
* Password: (Create a random password in 1Password with the maximum length and complexity allowed by the provider.)
* Ensure all secrets (passwords, generated API keys) are stored in Pulumi's 1Password vault.
* Enter any secrets consumed by integration tests as repository-level secrets in GitHub. These will be used by the integration tests during the CI/CD process.
1. Generate GitHub workflows per [the instructions in the ci-cmgmt repository](https://github.com/pulumi/ci-mgmt/#readme) and copy to `.github/` in this repository.
1. Copy the binary generated by the build and place it in your `$PATH` (`$GOPATH/bin` is a convenient choice), e.g.:

1. Copy the `pulumi-resource-foo` binary generated by `make provider` and place it in your `$PATH` (`$GOPATH/bin` is a convenient choice), e.g.:

```bash
cp bin/pulumi-resource-foo $GOPATH/bin
Expand All @@ -223,17 +222,30 @@ In this section, we will create a Pulumi program in TypeScript that utilizes the
```

1. Create a minimal program for the provider, i.e. one that creates the smallest-footprint resource. Place this code in `index.ts`.
1. Configure any necessary environment variables and ensure the program runs successfully via `pulumi up`.
1. Configure any necessary environment variables for authentication, e.g `$FOO_USERNAME`, `$FOO_TOKEN`, in your local environment.
1. Ensure the program runs successfully via `pulumi up`.
1. Once the program completes successfully, verify the resource was created in the provider's UI.
1. Destroy any resources created by the program via `pulumi destroy`.
Optionally, you may create additional examples for SDKs in other languages supported by Pulumi.
Optionally, you may create additional examples for SDKs in other languages supported by Pulumi:
## Configuring CI/CD with GitHub Actions
1. Python:
In this section, we'll add the necessary configuration to work with GitHub Actions for Pulumi's standard CI/CD workflows for providers.
```bash
mkdir examples/my-example/py
cd examples/my-example/py
pulumi new python
# (Go through the prompts with the default values)
source venv/bin/activate # use the virtual Python env that Pulumi sets up for you
pip install pulumi_foo
```
1. Follow the steps above to verify the program runs successfully.
## Add End-to-end Testing
We can run integration tests on our examples using the `*_test.go` files in the `examples/` folder.
1. Per the [README in the `ci-mgmt` repo](https://github.com/pulumi/ci-mgmt/#readme), generate the necessary GitHub Actions files and place them in the `.github/actions` directory in this repository.
1. Add code to `examples_nodejs_test.go` to call the example you created, e.g.:
```go
Expand All @@ -247,13 +259,43 @@ In this section, we'll add the necessary configuration to work with GitHub Actio
}
```
Add a similar function for each example that you want to run in an integration test. For examples written in other languages, create similar files for `examples_${LANGUAGE}_test.go`.
1. Ensure that any required secrets (API keys, etc.) are present in GitHub.
1. Add a similar function for each example that you want to run in an integration test. For examples written in other languages, create similar files for `examples_${LANGUAGE}_test.go`.
1. You can run these tests locally via Make:
```bash
make test
```
You can also run each test file separately via test tags:
```bash
cd examples && go test -v -tags=nodejs
```
## Configuring CI with GitHub Actions
In this section, we'll add the necessary configuration to work with GitHub Actions for Pulumi's standard CI/CD workflows for providers.
1. Generate GitHub workflows per [the instructions in the ci-mgmt repository](https://github.com/pulumi/ci-mgmt/) and copy to `.github/` in this repository.
1. Ensure that any required secrets are present as repository-level [secrets](https://docs.github.com/en/actions/security-guides/encrypted-secrets) in GitHub. These will be used by the integration tests during the CI/CD process.
## Final Steps
1. Ensure all required configurations (API keys, etc.) are documented in README-PROVIDER.md.
1. Replace this file with the README for the provider and push your changes:
```bash
mv README-PROVIDER.md README.md
```
1. If publishing the npm package fails during the "Publish SKDs" Action, perform the following steps:
1. Go to [NPM Packages](https://www.npmjs.com/) and sign in as pulumi-bot.
1. Click on the bot's profile pic and navigate to "Packages".
1. On the left, under "Organizations, click on the Pulumi organization.
1. On the last page of the listed packages, you should see the new package.
1. Under "Settings", set the Package Status to "public".
Now you are ready to use the provider, cut releases, and have some well-deserved :ice_cream:!

0 comments on commit f169979

Please sign in to comment.