Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor and add tests + cassettes #539

Merged
merged 12 commits into from
Jun 19, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
139 changes: 73 additions & 66 deletions datadog/cassettes/TestAccDatadogDashboardDistribution.yaml

Large diffs are not rendered by default.

162 changes: 81 additions & 81 deletions datadog/cassettes/TestAccDatadogDashboardDistribution_import.yaml

Large diffs are not rendered by default.

354 changes: 177 additions & 177 deletions datadog/cassettes/TestAccDatadogOrderedDashboard.yaml

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions datadog/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package datadog
import (
"context"
"fmt"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"io/ioutil"
"log"
"net/http"
Expand All @@ -20,6 +19,7 @@ import (
"github.com/dnaeon/go-vcr/recorder"
"github.com/hashicorp/go-cleanhttp"
"github.com/hashicorp/terraform-plugin-sdk/helper/logging"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
"github.com/jonboulle/clockwork"
Expand Down Expand Up @@ -284,14 +284,14 @@ func testCheckResourceAttrs(name string, checkExists resource.TestCheckFunc, ass
if len(assertionPair) > 1 {
value = assertionPair[1]
}
// Use utility method to print out all state values during debugging
funcs = append(funcs, resource.TestCheckResourceAttr(name, key, value))
// Use utility method below, instead of the above one, to print out all state keys/values during test debugging
//funcs = append(funcs, CheckResourceAttr(name, key, value))
gzussa marked this conversation as resolved.
Show resolved Hide resolved
}
return funcs
}

/* Utility method for Debugging purpose */
/* Utility method for Debugging purpose. This method helps list assertions as well */
func CheckResourceAttr(name, key, value string) resource.TestCheckFunc {
return func(s *terraform.State) error {
ms := s.RootModule()
Expand Down
13 changes: 11 additions & 2 deletions datadog/resource_datadog_dashboard_distribution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,16 @@ resource "datadog_dashboard" "distribution_dashboard" {
`

var datadogDashboardDistributionAsserts = []string{
"title = Acceptance Test Alert Graph Widget Dashboard",
"title = Acceptance Test Distribution Widget Dashboard",
"widget.0.distribution_definition.0.time.live_span = 1h",
"widget.0.distribution_definition.0.title = Avg of system.cpu.user over account:prod by service,account",
"widget.0.distribution_definition.0.title_size = 16",
"widget.0.distribution_definition.0.title_align = left",
"description = Created using the Datadog provider in Terraform",
"widget.0.distribution_definition.0.request.0.q = avg:system.cpu.user{account:prod} by {service,account}",
"widget.0.distribution_definition.0.request.0.style.0.palette = purple",
"layout_type = ordered",
"is_read_only = true",
}

func TestAccDatadogDashboardDistribution(t *testing.T) {
Expand All @@ -49,7 +58,7 @@ func TestAccDatadogDashboardDistribution(t *testing.T) {
CheckDestroy: checkDashboardDestroy(accProvider),
Steps: []resource.TestStep{
{
Config: datadogDashboardAlertGraphConfig,
Config: datadogDashboardDistributionConfig,
gzussa marked this conversation as resolved.
Show resolved Hide resolved
Check: resource.ComposeTestCheckFunc(
testCheckResourceAttrs("datadog_dashboard.distribution_dashboard", checkDashboardExists(accProvider), datadogDashboardDistributionAsserts)...,
),
Expand Down
26 changes: 13 additions & 13 deletions datadog/resource_datadog_dashboard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,12 @@ resource "datadog_dashboard" "ordered_dashboard" {
request {
log_query {
index = "mcnulty"
compute {
compute = {
aggregation = "count"
facet = "@duration"
interval = 5000
}
search {
search = {
query = "status:info"
}
group_by {
Expand All @@ -233,12 +233,12 @@ resource "datadog_dashboard" "ordered_dashboard" {
request {
apm_query {
index = "apm-search"
compute {
compute = {
aggregation = "count"
facet = "@duration"
interval = 5000
}
search {
search = {
query = "type:web"
}
group_by {
Expand Down Expand Up @@ -420,7 +420,7 @@ resource "datadog_dashboard" "free_dashboard" {
live_span = "1h"
}
}
layout {
layout = {
height = 43
width = 32
x = 5
Expand All @@ -437,7 +437,7 @@ resource "datadog_dashboard" "free_dashboard" {
live_span = "1h"
}
}
layout {
layout = {
height = 9
width = 65
x = 42
Expand All @@ -451,7 +451,7 @@ resource "datadog_dashboard" "free_dashboard" {
font_size = "88"
text_align = "left"
}
layout {
layout = {
height = 20
width = 30
x = 42
Expand All @@ -462,7 +462,7 @@ resource "datadog_dashboard" "free_dashboard" {
iframe_definition {
url = "http://google.com"
}
layout {
layout = {
height = 46
width = 39
x = 111
Expand All @@ -475,7 +475,7 @@ resource "datadog_dashboard" "free_dashboard" {
sizing = "fit"
margin = "small"
}
layout {
layout = {
height = 20
width = 30
x = 77
Expand All @@ -490,12 +490,12 @@ resource "datadog_dashboard" "free_dashboard" {
show_date_column = true
show_message_column = true
message_display = "expanded-md"
sort = {
sort {
column = "time"
order = "desc"
}
}
layout {
layout = {
height = 36
width = 32
x = 5
Expand All @@ -517,7 +517,7 @@ resource "datadog_dashboard" "free_dashboard" {
title_size = 16
title_align = "left"
}
layout {
layout = {
height = 40
width = 30
x = 112
Expand All @@ -544,7 +544,7 @@ resource "datadog_dashboard" "free_dashboard" {
live_span = "1h"
}
}
layout {
layout = {
height = 38
width = 67
x = 40
Expand Down