Skip to content

Commit

Permalink
add test coverage for logpush_job filter attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobbednarz committed Jun 15, 2022
1 parent 18ff5c0 commit 1197671
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 0 deletions.
9 changes: 9 additions & 0 deletions internal/app/cf-terraforming/cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,15 @@ func generateResources() func(cmd *cobra.Command, args []string) {
resourceCount = len(jsonPayload)
m, _ := json.Marshal(jsonPayload)
json.Unmarshal(m, &jsonStructData)

for i := 0; i < resourceCount; i++ {
// Workaround for LogpushJob.Filter being empty with a custom
// marshaler and returning `{"where":{}}` as the "empty" value.
if jsonStructData[i].(map[string]interface{})["filter"] == `{"where":{}}` {
jsonStructData[i].(map[string]interface{})["filter"] = nil
}
}

case "cloudflare_origin_ca_certificate":
jsonPayload, err := api.OriginCertificates(context.Background(), cloudflare.OriginCACertificateListOptions{ZoneID: zoneID})
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions internal/app/cf-terraforming/cmd/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ func TestResourceGeneration(t *testing.T) {
"cloudflare load balancer": {identiferType: "zone", resourceType: "cloudflare_load_balancer", testdataFilename: "cloudflare_load_balancer"},
"cloudflare load balancer pool": {identiferType: "account", resourceType: "cloudflare_load_balancer_pool", testdataFilename: "cloudflare_load_balancer_pool"},
"cloudflare logpush jobs": {identiferType: "zone", resourceType: "cloudflare_logpush_job", testdataFilename: "cloudflare_logpush_job"},
"cloudflare logpush jobs with filter": {identiferType: "zone", resourceType: "cloudflare_logpush_job", testdataFilename: "cloudflare_logpush_job_with_filter"},
"cloudflare origin CA certificate": {identiferType: "zone", resourceType: "cloudflare_origin_ca_certificate", testdataFilename: "cloudflare_origin_ca_certificate"},
"cloudflare page rule": {identiferType: "zone", resourceType: "cloudflare_page_rule", testdataFilename: "cloudflare_page_rule"},
"cloudflare rate limit": {identiferType: "zone", resourceType: "cloudflare_rate_limit", testdataFilename: "cloudflare_rate_limit"},
Expand Down
40 changes: 40 additions & 0 deletions testdata/cloudflare/cloudflare_logpush_job_with_filter.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
version: 1
interactions:
- request:
body: ""
form: {}
headers:
Content-Type:
- application/json
url: https://api.cloudflare.com/client/v4/zones/0da42c8d2132a9ddaf714f9e7c920711/logpush/jobs
method: GET
response:
body: |
{
"success": true,
"errors": [],
"messages": [],
"result": [
{
"id": 1,
"enabled": false,
"name": "example.com",
"dataset": "http_requests",
"filter": "{\"where\":{\"and\":[{\"key\":\"ClientRequestPath\",\"operator\":\"contains\",\"value\":\"/static\"},{\"key\":\"ClientRequestHost\",\"operator\":\"eq\",\"value\":\"example.com\"}]}}",
"logpull_options": "fields=RayID,ClientIP,EdgeStartTimestamp&timestamps=rfc3339",
"destination_conf": "s3://mybucket/logs?region=us-west-2",
"last_complete": null,
"last_error": null,
"error_message": null
}
]
}
headers:
Content-Type:
- application/json
Vary:
- Accept-Encoding
status: 200 OK
code: 200
duration: ""
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
terraform {
required_providers {
cloudflare = {
source = "cloudflare/cloudflare"
}
}
}
9 changes: 9 additions & 0 deletions testdata/terraform/cloudflare_logpush_job_with_filter/test.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
resource "cloudflare_logpush_job" "terraform_managed_resource" {
dataset = "http_requests"
destination_conf = "s3://mybucket/logs?region=us-west-2"
enabled = false
filter = "{\"where\":{\"and\":[{\"key\":\"ClientRequestPath\",\"operator\":\"contains\",\"value\":\"/static\"},{\"key\":\"ClientRequestHost\",\"operator\":\"eq\",\"value\":\"example.com\"}]}}"
logpull_options = "fields=RayID,ClientIP,EdgeStartTimestamp&timestamps=rfc3339"
name = "example.com"
zone_id = "0da42c8d2132a9ddaf714f9e7c920711"
}

0 comments on commit 1197671

Please sign in to comment.