latitudesh / terraform-provider-latitudesh

Latitude.sh Terraform Provider
https://registry.terraform.io/providers/latitudesh/latitudesh/latest/docs
Mozilla Public License 2.0
10 stars 4 forks source link

Feat: Record API calls with go-vcr and run tests in PRs #76

Closed ynhummel closed 3 months ago

ynhummel commented 3 months ago

What does this PR do?

The way we were testing Terraform had the downside of creating infrastructure. While this is useful for verifying that it is actually working, it leads to spamming the production environment.

To run these tests automatically on PRs, we will use Go-VCR to record API interactions and replay them. Although this does not guarantee 100% that the code is working, it at least ensures that if nothing has changed in the API, your code won’t break existing functionality.

Description of Task to be completed?

How should this be manually tested?

You can run the recorded tests locally with:

export LATITUDESH_TEST_SSH_PUBLIC_KEY="ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQC4y/S9agzMmMyXzSWYbuAuzt7sOKqz3IYZlph5KdNuqcL0JUJBtg1kf1uBpPTlavEZOPUHnN4Qfba5XEqgiEXogaq3PTbvk+Jte2Ui5DaC7bqreA9RlHFGVFxdG3g7PFTj5uddXfc/64m2UFWNxvcAGa11HBwY1UBTWS2k3PH1ZPIY97aHvIbubhBKdZa8DqGm7LKzwQxyx9+/VyRipE5xtwWkFs7AYOFYsFyIUfZy+WxB9+MpoUMQiPMZV9tFOud2mO4jlev442pJBPUnvnucQwwTmunJAih3u8bPLH7JFvbvTZx+rj39veHwwp6600pjZE+ysJsaOlZGejXTNUwDXXYSg/zfBMw5yTBY9otCw9wxvK72pHlJO6lLJbamZjfrOg/AW7I8KS4nZVuKOw3f1b+XA0x+p4aVbyaFaGCML23kckhKZ31berCoR8857pnxXwQPyqF5AicZi1HwfO54mmISRGPkwnc/Tf8gnA9PJao0qceO6YcDZGaU2U+gSo8hSnW9yl4kgsieY8qN5aKWrz8XYXhHutJyi+0MIVjulJ1ZVltgQHorNidQMOG8CPTZDJtyJm6XHzO3WpQC0voWXg+MdV4GYrqowWZc7z/kLSmCYX5UHGto+ZXRgrxzEcor5uW2TR2d+rsMWhLTW+5JgwlqKeXkygXvTrcfFbMdKw=="
export LATITUDESH_TEST_USER_DATA_CONTENT=bGF0aXR1ZGVzaCB1c2VyIGRhdGEgZXhhbXBsZQ==
export LATITUDESH_TEST_SERVER_ID=sv_PVwea4wdR5B9O
export LATITUDESH_TEST_VIRTUAL_NETWORK_ID=vlan_M3Beab6eyaLnb
export LATITUDESH_AUTH_TOKEN=test
export LATITUDESH_TEST_PROJECT=proj_ogXka9v7m0JdB

TF_ACC=1 LATITUDE_TEST_RECORDER=play go test ./... -v -timeout 10m

The data used in these variables is either fake or from resources that were created solely for recording the interaction and then promptly deleted.

Any background context you want to provide?

What are the relevant GitHub issues (if any)?

Screenshots (if appropriate):

Questions: