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 30, 2024
1 parent 2ce33d0 commit f6e82ff
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 13 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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/hashicorp/go-slug v0.13.3
github.com/hashicorp/go-uuid v1.0.3
github.com/hashicorp/go-version v1.6.0
github.com/hashicorp/jsonapi v1.2.0
github.com/hashicorp/jsonapi v1.3.0
github.com/stretchr/testify v1.8.4
golang.org/x/sync v0.6.0
golang.org/x/time v0.5.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/C
github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
github.com/hashicorp/go-version v1.6.0 h1:feTTfFNnjP967rlCxM/I9g701jU+RN74YKx2mOkIeek=
github.com/hashicorp/go-version v1.6.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
github.com/hashicorp/jsonapi v1.2.0 h1:ezDCzOFsKTL+KxVQuA1rNxkIGTvZph1rNu8kT5A8trI=
github.com/hashicorp/jsonapi v1.2.0/go.mod h1:Yog5+CPEM3c99L1CL2CFCYoSzgWm5vTU58idbRUaLik=
github.com/hashicorp/jsonapi v1.3.0 h1:4d7xWWdwJGm5bbP/sbDsqe6Kn6LERVr7sLEQxa6NR+w=
github.com/hashicorp/jsonapi v1.3.0/go.mod h1:kWfdn49yCjQvbpnvY1dxxAuAFzISwrrMDQOcu6NsFoM=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
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 f6e82ff

Please sign in to comment.