Skip to content

Commit

Permalink
workaround time.Now since we match on body now
Browse files Browse the repository at this point in the history
  • Loading branch information
zippolyte committed Nov 20, 2020
1 parent d4502c8 commit f3bb0be
Show file tree
Hide file tree
Showing 37 changed files with 4,896 additions and 4,895 deletions.
2 changes: 1 addition & 1 deletion datadog/cassettes/TestAccDatadogMonitorDatasource.freeze
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2020-08-18T09:54:17.502646+02:00
2020-11-20T13:06:49.23369+01:00
880 changes: 440 additions & 440 deletions datadog/cassettes/TestAccDatadogMonitorDatasource.yaml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
2020-08-18T09:54:17.505066+02:00
2020-11-20T13:06:49.23899+01:00
316 changes: 158 additions & 158 deletions datadog/cassettes/TestAccDatadogMonitorServiceCheck_Basic.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion datadog/cassettes/TestAccDatadogMonitor_Basic.freeze
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2020-08-18T09:54:17.503939+02:00
2020-11-20T13:06:49.23701+01:00
316 changes: 158 additions & 158 deletions datadog/cassettes/TestAccDatadogMonitor_Basic.yaml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
2020-08-18T09:54:17.506173+02:00
2020-11-20T13:06:49.242669+01:00
302 changes: 151 additions & 151 deletions datadog/cassettes/TestAccDatadogMonitor_BasicNoTreshold.yaml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
2020-08-18T09:54:17.512283+02:00
2020-11-20T13:06:49.250365+01:00
590 changes: 295 additions & 295 deletions datadog/cassettes/TestAccDatadogMonitor_Basic_float_int.yaml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
2020-08-18T09:54:17.517986+02:00
2020-11-20T13:06:49.263781+01:00
722 changes: 361 additions & 361 deletions datadog/cassettes/TestAccDatadogMonitor_ComposeWithSyntheticsTest.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion datadog/cassettes/TestAccDatadogMonitor_Log.freeze
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2020-08-18T09:54:17.513461+02:00
2020-11-20T13:06:49.252321+01:00
302 changes: 151 additions & 151 deletions datadog/cassettes/TestAccDatadogMonitor_Log.yaml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
2020-08-18T09:54:17.516915+02:00
2020-11-20T13:06:49.260369+01:00
620 changes: 310 additions & 310 deletions datadog/cassettes/TestAccDatadogMonitor_MuteUnmuteSpecificScopes.yaml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
2020-08-18T09:54:17.514654+02:00
2020-11-20T13:06:49.254053+01:00
302 changes: 151 additions & 151 deletions datadog/cassettes/TestAccDatadogMonitor_NoThresholdWindows.yaml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
2020-08-18T09:54:17.519109+02:00
2020-11-20T13:06:49.265647+01:00
620 changes: 310 additions & 310 deletions datadog/cassettes/TestAccDatadogMonitor_SilencedRemove.yaml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
2020-08-18T09:54:17.520211+02:00
2020-11-20T13:06:49.267493+01:00
464 changes: 232 additions & 232 deletions datadog/cassettes/TestAccDatadogMonitor_SilencedUpdateNoDiff.yaml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
2020-08-18T09:54:17.521316+02:00
2020-11-20T13:06:49.269205+01:00
730 changes: 365 additions & 365 deletions datadog/cassettes/TestAccDatadogMonitor_SilencedUpdatePastTimestamp.yaml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
2020-08-18T09:54:17.515821+02:00
2020-11-20T13:06:49.256425+01:00
302 changes: 151 additions & 151 deletions datadog/cassettes/TestAccDatadogMonitor_ThresholdWindows.yaml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
2020-08-18T09:54:17.511122+02:00
2020-11-20T13:06:49.24797+01:00
302 changes: 151 additions & 151 deletions datadog/cassettes/TestAccDatadogMonitor_TrimWhitespace.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion datadog/cassettes/TestAccDatadogMonitor_Updated.freeze
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2020-08-18T09:54:17.507312+02:00
2020-11-20T13:06:49.244543+01:00
1,342 changes: 671 additions & 671 deletions datadog/cassettes/TestAccDatadogMonitor_Updated.yaml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1 +1 @@
2020-08-18T09:54:17.508434+02:00
2020-11-20T13:06:49.246309+01:00
1,362 changes: 681 additions & 681 deletions datadog/cassettes/TestAccDatadogMonitor_UpdatedToRemoveTags.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion datadog/cassettes/TestAccDatadogMonitor_ZeroDelay.freeze
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2020-10-28T10:50:13.946105+01:00
2020-11-20T13:06:49.270867+01:00
267 changes: 130 additions & 137 deletions datadog/cassettes/TestAccDatadogMonitor_ZeroDelay.yaml

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions datadog/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"net/url"
"runtime"
"strings"
"time"

datadogV1 "github.com/DataDog/datadog-api-client-go/api/v1/datadog"
datadogV2 "github.com/DataDog/datadog-api-client-go/api/v2/datadog"
Expand Down Expand Up @@ -102,6 +103,12 @@ type ProviderConfiguration struct {
DatadogClientV2 *datadogV2.APIClient
AuthV1 context.Context
AuthV2 context.Context

now func() time.Time
}

func (p *ProviderConfiguration) Now() time.Time {
return p.now()
}

func providerConfigure(d *schema.ResourceData) (interface{}, error) {
Expand Down
6 changes: 4 additions & 2 deletions datadog/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ func initAccProvider(ctx context.Context, t *testing.T, httpClient *http.Client)
defer finish()

p := Provider().(*schema.Provider)
p.ConfigureFunc = testProviderConfigure(ctx, httpClient)
p.ConfigureFunc = testProviderConfigure(ctx, httpClient, testClock(t))

return p
}
Expand Down Expand Up @@ -429,7 +429,7 @@ func buildDatadogClientV2(httpClient *http.Client) *datadogV2.APIClient {
return datadogV2.NewAPIClient(configV2)
}

func testProviderConfigure(ctx context.Context, httpClient *http.Client) schema.ConfigureFunc {
func testProviderConfigure(ctx context.Context, httpClient *http.Client, clock clockwork.FakeClock) schema.ConfigureFunc {
return func(d *schema.ResourceData) (interface{}, error) {
communityClient := datadogCommunity.NewClient(d.Get("api_key").(string), d.Get("app_key").(string))
if apiURL := d.Get("api_url").(string); apiURL != "" {
Expand Down Expand Up @@ -458,6 +458,8 @@ func testProviderConfigure(ctx context.Context, httpClient *http.Client) schema.
DatadogClientV2: buildDatadogClientV2(c),
AuthV1: ctx,
AuthV2: ctx,

now: clock.Now,
}, nil
}
}
Expand Down
5 changes: 2 additions & 3 deletions datadog/resource_datadog_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"sort"
"strconv"
"strings"
"time"

datadogV1 "github.com/DataDog/datadog-api-client-go/api/v1/datadog"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
Expand Down Expand Up @@ -509,7 +508,7 @@ func resourceDatadogMonitorRead(d *schema.ResourceData, meta interface{}) error

// Ignore any timestamps in the past that aren't -1 or 0
for k, v := range configSilenced {
if v.(int) < int(time.Now().Unix()) && v.(int) != 0 && v.(int) != -1 {
if v.(int) < int(providerConf.Now().Unix()) && v.(int) != 0 && v.(int) != -1 {
// sync the state with whats in the config so its ignored
apiSilenced[k] = int64(v.(int))
}
Expand Down Expand Up @@ -568,7 +567,7 @@ func resourceDatadogMonitorUpdate(d *schema.ResourceData, meta interface{}) erro
for k, _ := range mSilenced {
// Since the Datadog GO client doesn't support unmuting on all scopes, loop over GetSilenced() and set the
// end timestamp to time.Now().Unix()
mSilenced[k] = time.Now().Unix()
mSilenced[k] = providerConf.Now().Unix()
}
monitorResp, _, err = datadogClientV1.MonitorsApi.UpdateMonitor(authV1, i).Body(*m).Execute()
if err != nil {
Expand Down

0 comments on commit f3bb0be

Please sign in to comment.