Skip to content

Commit

Permalink
Merge pull request #121 from hashicorp/radditude/new-cost-estimation-…
Browse files Browse the repository at this point in the history
…status
  • Loading branch information
radditude authored May 19, 2020
2 parents 2faaed6 + ba84f54 commit 115548c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 11 deletions.
24 changes: 13 additions & 11 deletions cost_estimate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down
9 changes: 9 additions & 0 deletions tfe.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 6 additions & 0 deletions tfe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})
}

Expand Down

0 comments on commit 115548c

Please sign in to comment.