Skip to content

Commit

Permalink
feat: added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kelvintaywl committed Feb 10, 2023
1 parent e9ebdc8 commit 733d831
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 1 deletion.
17 changes: 17 additions & 0 deletions README.md
Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions 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:
4 changes: 3 additions & 1 deletion internal/provider/provider_test.go
Expand Up @@ -13,7 +13,9 @@ const (
providerConfig = `
provider "circleci" {
api_token = "fooBar"
hostname = "circleci.example.com"
// see docker-compose.yml
hostname = "localhost:8080"
https = false
}
`
)
Expand Down
36 changes: 36 additions & 0 deletions 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"),
),
},
},
})
}
7 changes: 7 additions & 0 deletions nginx/testacc.conf
@@ -0,0 +1,7 @@
server {
listen 80;

location /api/v2/ {
proxy_pass http://prism:4010/;
}
}

0 comments on commit 733d831

Please sign in to comment.