forked from hashicorp/go-tfe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcost_estimate_test.go
49 lines (40 loc) · 1.26 KB
/
cost_estimate_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package tfe
import (
"context"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestCostEstimatesRead(t *testing.T) {
client := testClient(t)
ctx := context.Background()
orgTest, orgTestCleanup := createOrganization(t, client)
defer orgTestCleanup()
// Enable cost estimation for the test organization.
orgTest, err := client.Organizations.Update(
ctx,
orgTest.Name,
OrganizationUpdateOptions{
CostEstimationEnabled: Bool(true),
},
)
require.NoError(t, err)
wTest, _ := createWorkspace(t, client, orgTest)
rTest, _ := createCostEstimatedRun(t, client, wTest)
t.Run("when the costEstimate exists", func(t *testing.T) {
ce, err := client.CostEstimates.Read(ctx, rTest.CostEstimate.ID)
require.NoError(t, err)
assert.Equal(t, ce.Status, CostEstimateFinished)
assert.NotEmpty(t, ce.StatusTimestamps)
})
t.Run("when the costEstimate does not exist", func(t *testing.T) {
ce, err := client.CostEstimates.Read(ctx, "nonexisting")
assert.Nil(t, ce)
assert.Equal(t, ErrResourceNotFound, err)
})
t.Run("with invalid costEstimate ID", func(t *testing.T) {
ce, err := client.CostEstimates.Read(ctx, badIdentifier)
assert.Nil(t, ce)
assert.EqualError(t, err, "invalid value for cost estimate ID")
})
}