Skip to content

Commit

Permalink
chore: bump jsonapi version
Browse files Browse the repository at this point in the history
  • Loading branch information
ctrombley committed Jan 31, 2024
1 parent 000432d commit 46d092a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
7 changes: 3 additions & 4 deletions examples/workspaces/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"time"

tfe "github.com/hashicorp/go-tfe"
"github.com/hashicorp/jsonapi"
)

func main() {
Expand All @@ -29,7 +28,7 @@ func main() {
// Create a new workspace
w, err := client.Workspaces.Create(ctx, "org-name", tfe.WorkspaceCreateOptions{
Name: tfe.String("my-app-tst"),
AutoDestroyAt: jsonapi.NullableTime(time.Date(2025, 1, 1, 0, 0, 0, 0, time.UTC)),
AutoDestroyAt: tfe.NullableTime(time.Date(2025, 1, 1, 0, 0, 0, 0, time.UTC)),
})
if err != nil {
log.Fatal(err)
Expand All @@ -40,15 +39,15 @@ func main() {
AutoApply: tfe.Bool(false),
TerraformVersion: tfe.String("0.11.1"),
WorkingDirectory: tfe.String("my-app/infra"),
AutoDestroyAt: jsonapi.NullableTime(time.Date(2025, 1, 1, 0, 0, 0, 0, time.UTC)),
AutoDestroyAt: tfe.NullableTime(time.Date(2025, 1, 1, 0, 0, 0, 0, time.UTC)),
})
if err != nil {
log.Fatal(err)
}

// Disable auto destroy
w, err = client.Workspaces.Update(ctx, "org-name", w.Name, tfe.WorkspaceUpdateOptions{
AutoDestroyAt: jsonapi.NullTime(),
AutoDestroyAt: tfe.NullTime(),
})
if err != nil {
log.Fatal(err)
Expand Down
22 changes: 22 additions & 0 deletions type_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@

package tfe

import (
"time"

"github.com/hashicorp/jsonapi"
)

// Access returns a pointer to the given team access type.
func Access(v AccessType) *AccessType {
return &v
Expand Down Expand Up @@ -117,3 +123,19 @@ func SMTPAuthValue(v SMTPAuthType) *SMTPAuthType {
func String(v string) *string {
return &v
}

func NullableBool(v bool) jsonapi.NullableAttr[bool] {
return jsonapi.NewNullableAttrWithValue[bool](v)
}

func NullBool() jsonapi.NullableAttr[bool] {
return jsonapi.NewNullNullableAttr[bool]()
}

func NullableTime(v time.Time) jsonapi.NullableAttr[time.Time] {
return jsonapi.NewNullableAttrWithValue[time.Time](v)
}

func NullTime() jsonapi.NullableAttr[time.Time] {
return jsonapi.NewNullNullableAttr[time.Time]()
}
11 changes: 5 additions & 6 deletions workspace_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"time"

retryablehttp "github.com/hashicorp/go-retryablehttp"
"github.com/hashicorp/jsonapi"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -540,7 +539,7 @@ func TestWorkspacesCreate(t *testing.T) {
Name: String(fmt.Sprintf("foo-%s", randomString(t))),
AllowDestroyPlan: Bool(true),
AutoApply: Bool(true),
AutoDestroyAt: jsonapi.NullableTime(time.Date(2025, 1, 1, 0, 0, 0, 0, time.UTC)),
AutoDestroyAt: NullableTime(time.Date(2025, 1, 1, 0, 0, 0, 0, time.UTC)),
Description: String("qux"),
AssessmentsEnabled: Bool(false),
FileTriggersEnabled: Bool(true),
Expand Down Expand Up @@ -1127,7 +1126,7 @@ func TestWorkspacesUpdate(t *testing.T) {
Name: String(randomString(t)),
AllowDestroyPlan: Bool(true),
AutoApply: Bool(false),
AutoDestroyAt: jsonapi.NullableTime(time.Date(2025, 1, 1, 0, 0, 0, 0, time.UTC)),
AutoDestroyAt: NullableTime(time.Date(2025, 1, 1, 0, 0, 0, 0, time.UTC)),
FileTriggersEnabled: Bool(true),
Operations: Bool(false),
QueueAllRuns: Bool(false),
Expand Down Expand Up @@ -2659,7 +2658,7 @@ func TestWorkspacesAutoDestroy(t *testing.T) {

upgradeOrganizationSubscription(t, client, orgTest)

autoDestroyAt := jsonapi.NullableTime(time.Date(2025, 1, 1, 0, 0, 0, 0, time.UTC))
autoDestroyAt := NullableTime(time.Date(2025, 1, 1, 0, 0, 0, 0, time.UTC))
wTest, wCleanup := createWorkspaceWithOptions(t, client, orgTest, WorkspaceCreateOptions{
Name: String(randomString(t)),
AutoDestroyAt: autoDestroyAt,
Expand All @@ -2678,7 +2677,7 @@ func TestWorkspacesAutoDestroy(t *testing.T) {

// explicitly update the value of auto_destroy_at
w, err = client.Workspaces.Update(ctx, orgTest.Name, wTest.Name, WorkspaceUpdateOptions{
AutoDestroyAt: jsonapi.NullableTime(time.Date(2025, 1, 2, 0, 0, 0, 0, time.UTC)),
AutoDestroyAt: NullableTime(time.Date(2025, 1, 2, 0, 0, 0, 0, time.UTC)),
})

require.NoError(t, err)
Expand All @@ -2687,7 +2686,7 @@ func TestWorkspacesAutoDestroy(t *testing.T) {

// disable auto destroy
w, err = client.Workspaces.Update(ctx, orgTest.Name, wTest.Name, WorkspaceUpdateOptions{
AutoDestroyAt: jsonapi.NullTime(),
AutoDestroyAt: NullTime(),
})

require.NoError(t, err)
Expand Down

0 comments on commit 46d092a

Please sign in to comment.