From 3c73d4b596d0f07f9f9c7af71cae0ffaf3c4418d Mon Sep 17 00:00:00 2001 From: CJ Horton <17039873+radditude@users.noreply.github.com> Date: Mon, 18 May 2020 09:50:19 -0700 Subject: [PATCH 1/2] add new cost estimation status for targeting --- cost_estimate.go | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/cost_estimate.go b/cost_estimate.go index b0ccecfb4..c7f33493f 100644 --- a/cost_estimate.go +++ b/cost_estimate.go @@ -33,13 +33,14 @@ type costEstimates struct { // CostEstimateStatus represents a costEstimate state. type CostEstimateStatus string -//List all available costEstimate statuses. +// List all available costEstimate statuses. const ( - CostEstimateCanceled CostEstimateStatus = "canceled" - CostEstimateErrored CostEstimateStatus = "errored" - CostEstimateFinished CostEstimateStatus = "finished" - CostEstimatePending CostEstimateStatus = "pending" - CostEstimateQueued CostEstimateStatus = "queued" + CostEstimateCanceled CostEstimateStatus = "canceled" + CostEstimateErrored CostEstimateStatus = "errored" + CostEstimateFinished CostEstimateStatus = "finished" + CostEstimatePending CostEstimateStatus = "pending" + CostEstimateQueued CostEstimateStatus = "queued" + CostEstimateSkippedDueToTargeting CostEstimateStatus = "skipped_due_to_targeting" ) // CostEstimate represents a Terraform Enterprise costEstimate. @@ -58,11 +59,12 @@ type CostEstimate struct { // CostEstimateStatusTimestamps holds the timestamps for individual costEstimate statuses. type CostEstimateStatusTimestamps struct { - CanceledAt time.Time `json:"canceled-at"` - ErroredAt time.Time `json:"errored-at"` - FinishedAt time.Time `json:"finished-at"` - PendingAt time.Time `json:"pending-at"` - QueuedAt time.Time `json:"queued-at"` + CanceledAt time.Time `json:"canceled-at"` + ErroredAt time.Time `json:"errored-at"` + FinishedAt time.Time `json:"finished-at"` + PendingAt time.Time `json:"pending-at"` + QueuedAt time.Time `json:"queued-at"` + SkippedDueToTargetingAt time.Time `json:"skipped-due-to-targeting-at"` } // Read a costEstimate by its ID. From ba84f549b605de8f3cfbd9c99db9aaeeb1b4ef34 Mon Sep 17 00:00:00 2001 From: CJ Horton <17039873+radditude@users.noreply.github.com> Date: Mon, 18 May 2020 09:50:50 -0700 Subject: [PATCH 2/2] add utility for testing API versions --- tfe.go | 9 +++++++++ tfe_test.go | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/tfe.go b/tfe.go index 5883d9d87..ca2f12d13 100644 --- a/tfe.go +++ b/tfe.go @@ -259,6 +259,15 @@ func (c *Client) RemoteAPIVersion() string { return c.remoteAPIVersion } +// SetFakeRemoteAPIVersion allows setting a given string as the client's remoteAPIVersion, +// overriding the value pulled from the API header during client initialization. +// +// This is intended for use in tests, when you may want to configure your TFE client to +// return something different than the actual API version in order to test error handling. +func (c *Client) SetFakeRemoteAPIVersion(fakeAPIVersion string) { + c.remoteAPIVersion = fakeAPIVersion +} + // RetryServerErrors configures the retry HTTP check to also retry // unexpected errors or requests that failed with a server error. func (c *Client) RetryServerErrors(retry bool) { diff --git a/tfe_test.go b/tfe_test.go index e8e25a7ca..10bc0477f 100644 --- a/tfe_test.go +++ b/tfe_test.go @@ -73,6 +73,12 @@ func TestClient_newClient(t *testing.T) { if want := "34.21.9"; client.RemoteAPIVersion() != want { t.Errorf("unexpected remote API version %q; want %q", client.RemoteAPIVersion(), want) } + + client.SetFakeRemoteAPIVersion("1.0") + + if want := "1.0"; client.RemoteAPIVersion() != want { + t.Errorf("unexpected remote API version %q; want %q", client.RemoteAPIVersion(), want) + } }) }