Skip to content

Commit

Permalink
Use 45 seconds as default for all runs
Browse files Browse the repository at this point in the history
  • Loading branch information
Sander van Harmelen committed Apr 24, 2019
1 parent 222a23d commit 20ff794
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 24 deletions.
10 changes: 4 additions & 6 deletions cost_estimation.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,9 @@ const (
// CostEstimation represents a Terraform Enterprise costEstimation.
type CostEstimation struct {
ID string `jsonapi:"primary,cost-estimations"`
LogReadURL string `jsonapi:"attr,log-read-url"`
ErrorMessage string `jsonapi:"attr,error-message"`
Status CostEstimationStatus `jsonapi:"attr,status"`
StatusTimestamps *CostEstimationStatusTimestamps `jsonapi:"attr,status-timestamps"`
ErrorMessage string `jsonapi:"attr,error-message"`
// Costs *CostEstimationCosts `jsonapi:"attr,costs"`
}

// CostEstimationStatusTimestamps holds the timestamps for individual costEstimation statuses.
Expand All @@ -71,13 +69,13 @@ func (s *costEstimations) Read(ctx context.Context, costEstimationID string) (*C
return nil, err
}

p := &CostEstimation{}
err = s.client.do(ctx, req, p)
ce := &CostEstimation{}
err = s.client.do(ctx, req, ce)
if err != nil {
return nil, err
}

return p, nil
return ce, nil
}

// Logs retrieves the logs of a costEstimation.
Expand Down
25 changes: 13 additions & 12 deletions cost_estimation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,21 @@ func TestCostEstimationsRead(t *testing.T) {
rTest, _ := createPlannedRun(t, client, wTest)

t.Run("when the costEstimation exists", func(t *testing.T) {
p, err := client.CostEstimations.Read(ctx, rTest.CostEstimation.ID)
ce, err := client.CostEstimations.Read(ctx, rTest.CostEstimation.ID)
require.NoError(t, err)
assert.NotEmpty(t, p.LogReadURL)
assert.Equal(t, p.Status, CostEstimationFinished)
assert.NotEmpty(t, p.StatusTimestamps)
assert.Equal(t, ce.Status, CostEstimationFinished)
assert.NotEmpty(t, ce.StatusTimestamps)
})

t.Run("when the costEstimation does not exist", func(t *testing.T) {
p, err := client.CostEstimations.Read(ctx, "nonexisting")
assert.Nil(t, p)
assert.Equal(t, err, ErrResourceNotFound)
ce, err := client.CostEstimations.Read(ctx, "nonexisting")
assert.Nil(t, ce)
assert.Equal(t, ErrResourceNotFound, err)
})

t.Run("with invalid costEstimation ID", func(t *testing.T) {
p, err := client.CostEstimations.Read(ctx, badIdentifier)
assert.Nil(t, p)
ce, err := client.CostEstimations.Read(ctx, badIdentifier)
assert.Nil(t, ce)
assert.EqualError(t, err, "invalid value for cost estimation ID")
})
}
Expand All @@ -71,16 +70,18 @@ func TestCostEstimationsLogs(t *testing.T) {
rTest, _ := createPlannedRun(t, client, wTest)

t.Run("when the log exists", func(t *testing.T) {
p, err := client.CostEstimations.Read(ctx, rTest.CostEstimation.ID)
ce, err := client.CostEstimations.Read(ctx, rTest.CostEstimation.ID)
require.NoError(t, err)

logReader, err := client.CostEstimations.Logs(ctx, p.ID)
logReader, err := client.CostEstimations.Logs(ctx, ce.ID)
require.NotNil(t, logReader)
require.NoError(t, err)

logs, err := ioutil.ReadAll(logReader)
require.NoError(t, err)

assert.Contains(t, string(logs), "+----")
t.Skip("log output is likely to change")
assert.Contains(t, string(logs), "SKU")
})

t.Run("when the log does not exist", func(t *testing.T) {
Expand Down
11 changes: 5 additions & 6 deletions helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ func createOAuthToken(t *testing.T, client *Client, org *Organization) (*OAuthTo
func createOrganization(t *testing.T, client *Client) (*Organization, func()) {
ctx := context.Background()
org, err := client.Organizations.Create(ctx, OrganizationCreateOptions{
Name: String("go-" + randomString(t)),
Name: String("tst-" + randomString(t)),
Email: String(fmt.Sprintf("%[email protected]", randomString(t))),
})
if err != nil {
Expand Down Expand Up @@ -349,7 +349,7 @@ func createPlannedRun(t *testing.T, client *Client, w *Workspace) (*Run, func())

if i > 45 {
rCleanup()
t.Fatal("45 second timeout waiting for run to be planned")
t.Fatal("Timeout waiting for run to be applied")
}

time.Sleep(1 * time.Second)
Expand All @@ -372,19 +372,18 @@ func createAppliedRun(t *testing.T, client *Client, w *Workspace) (*Run, func())
}

if r.Status == RunApplied {
break
return r, rCleanup
}

if i > 30 {
if i > 45 {
rCleanup()
t.Fatal("Timeout waiting for run to be applied")
}

time.Sleep(1 * time.Second)
}

return r, rCleanup
}

func createSSHKey(t *testing.T, client *Client, org *Organization) (*SSHKey, func()) {
var orgCleanup func()

Expand Down

0 comments on commit 20ff794

Please sign in to comment.