diff --git a/README.md b/README.md index 1c2131e..59eb943 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,23 @@ $ make tf.apply $ make tf.destroy ``` +### Testing locally + +**Note**: This project uses a mock server, via [Prism](https://stoplight.io/open-source/prism), in place of circleci.com. +Refer to the [Docker Compose file](docker-compose.yml) for details. + +```console + +# start mock server +$ docker-compose up -d + +# wait for Nginx and Prism to be ready + +# Run acceptance tests +$ make testacc +``` + + ## Docs ```console diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..4443a6c --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,25 @@ +version: "3" + +services: + # fake CircleCI server + prism: + image: stoplight/prism:4 + command: 'mock -h 0.0.0.0 https://raw.githubusercontent.com/kelvintaywl/circleci-webhook-go-sdk/main/openapi.yaml' + networks: + - prism + expose: + - "4010" + nginx: + image: nginx + networks: + - prism + ports: + - "8080:80" + depends_on: + - prism + volumes: + # Override default config to act as TLS proxy + - ./nginx/testacc.conf:/etc/nginx/conf.d/default.conf:ro + +networks: + prism: diff --git a/internal/provider/provider_test.go b/internal/provider/provider_test.go index e7a01cb..a8f3ac7 100644 --- a/internal/provider/provider_test.go +++ b/internal/provider/provider_test.go @@ -13,7 +13,9 @@ const ( providerConfig = ` provider "circleci" { api_token = "fooBar" - hostname = "circleci.example.com" + // see docker-compose.yml + hostname = "localhost:8080" + https = false } ` ) diff --git a/internal/provider/webhooks_data_source_test.go b/internal/provider/webhooks_data_source_test.go new file mode 100644 index 0000000..5c5cff0 --- /dev/null +++ b/internal/provider/webhooks_data_source_test.go @@ -0,0 +1,36 @@ +package provider + +import ( + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" +) + +func TestAccWebhooksDataSource(t *testing.T) { + resource.Test(t, resource.TestCase{ + ProtoV6ProviderFactories: testAccProtoV6ProviderFactories, + Steps: []resource.TestStep{ + // Read testing + { + // github/kelvintaywl-cci/tf-provider-acceptance-test-dummy + Config: providerConfig + ` +data "circleci_webhooks" "test" { + project_id = "c124cca6-d03e-4733-b84d-32b02347b78c" +}`, + Check: resource.ComposeAggregateTestCheckFunc( + // top level + resource.TestCheckResourceAttr("data.circleci_webhooks.test", "id", "c124cca6-d03e-4733-b84d-32b02347b78c"), + resource.TestCheckResourceAttr("data.circleci_webhooks.test", "webhooks.#", "1"), + // webhook + resource.TestCheckResourceAttr("data.circleci_webhooks.test", "webhooks.0.id", "string"), + resource.TestCheckResourceAttr("data.circleci_webhooks.test", "webhooks.0.name", "string"), + resource.TestCheckResourceAttr("data.circleci_webhooks.test", "webhooks.0.verify_tls", "true"), + resource.TestCheckResourceAttr("data.circleci_webhooks.test", "webhooks.0.signing_secret", "string"), + resource.TestCheckResourceAttr("data.circleci_webhooks.test", "webhooks.0.scope.id", "string"), + resource.TestCheckResourceAttr("data.circleci_webhooks.test", "webhooks.0.scope.type", "project"), + resource.TestCheckResourceAttr("data.circleci_webhooks.test", "webhooks.0.events.0", "workflow-completed"), + ), + }, + }, + }) +} diff --git a/nginx/testacc.conf b/nginx/testacc.conf new file mode 100644 index 0000000..7eac97c --- /dev/null +++ b/nginx/testacc.conf @@ -0,0 +1,7 @@ +server { + listen 80; + + location /api/v2/ { + proxy_pass http://prism:4010/; + } +}