Skip to content

chore: replace PtrTo with ptr.Ref #132

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions internal/provider/group_data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"testing"
"text/template"

"github.com/coder/coder/v2/coderd/util/ptr"
"github.com/coder/coder/v2/codersdk"
"github.com/coder/terraform-provider-coderd/integration"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
Expand Down Expand Up @@ -74,7 +75,7 @@ func TestAccGroupDataSource(t *testing.T) {
cfg := testAccGroupDataSourceConfig{
URL: client.URL.String(),
Token: client.SessionToken(),
ID: PtrTo(group.ID.String()),
ID: ptr.Ref(group.ID.String()),
}
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand All @@ -92,8 +93,8 @@ func TestAccGroupDataSource(t *testing.T) {
cfg := testAccGroupDataSourceConfig{
URL: client.URL.String(),
Token: client.SessionToken(),
OrganizationID: PtrTo(firstUser.OrganizationIDs[0].String()),
Name: PtrTo("example-group"),
OrganizationID: ptr.Ref(firstUser.OrganizationIDs[0].String()),
Name: ptr.Ref("example-group"),
}
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand All @@ -111,7 +112,7 @@ func TestAccGroupDataSource(t *testing.T) {
cfg := testAccGroupDataSourceConfig{
URL: client.URL.String(),
Token: client.SessionToken(),
Name: PtrTo("example-group"),
Name: ptr.Ref("example-group"),
}
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand All @@ -129,7 +130,7 @@ func TestAccGroupDataSource(t *testing.T) {
cfg := testAccGroupDataSourceConfig{
URL: client.URL.String(),
Token: client.SessionToken(),
OrganizationID: PtrTo(firstUser.OrganizationIDs[0].String()),
OrganizationID: ptr.Ref(firstUser.OrganizationIDs[0].String()),
}
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand Down
27 changes: 14 additions & 13 deletions internal/provider/group_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"testing"
"text/template"

"github.com/coder/coder/v2/coderd/util/ptr"
"github.com/coder/coder/v2/codersdk"
"github.com/coder/terraform-provider-coderd/integration"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
Expand Down Expand Up @@ -44,17 +45,17 @@ func TestAccGroupResource(t *testing.T) {
cfg1 := testAccGroupResourceconfig{
URL: client.URL.String(),
Token: client.SessionToken(),
Name: PtrTo("example-group"),
DisplayName: PtrTo("Example Group"),
AvatarUrl: PtrTo("https://google.com"),
QuotaAllowance: PtrTo(int32(100)),
Members: PtrTo([]string{user1.ID.String()}),
Name: ptr.Ref("example-group"),
DisplayName: ptr.Ref("Example Group"),
AvatarUrl: ptr.Ref("https://google.com"),
QuotaAllowance: ptr.Ref(int32(100)),
Members: ptr.Ref([]string{user1.ID.String()}),
}

cfg2 := cfg1
cfg2.Name = PtrTo("example-group-new")
cfg2.DisplayName = PtrTo("Example Group New")
cfg2.Members = PtrTo([]string{user2.ID.String()})
cfg2.Name = ptr.Ref("example-group-new")
cfg2.DisplayName = ptr.Ref("Example Group New")
cfg2.Members = ptr.Ref([]string{user2.ID.String()})

cfg3 := cfg2
cfg3.Members = nil
Expand Down Expand Up @@ -143,11 +144,11 @@ func TestAccGroupResourceAGPL(t *testing.T) {
cfg1 := testAccGroupResourceconfig{
URL: client.URL.String(),
Token: client.SessionToken(),
Name: PtrTo("example-group"),
DisplayName: PtrTo("Example Group"),
AvatarUrl: PtrTo("https://google.com"),
QuotaAllowance: PtrTo(int32(100)),
Members: PtrTo([]string{firstUser.ID.String()}),
Name: ptr.Ref("example-group"),
DisplayName: ptr.Ref("Example Group"),
AvatarUrl: ptr.Ref("https://google.com"),
QuotaAllowance: ptr.Ref(int32(100)),
Members: ptr.Ref([]string{firstUser.ID.String()}),
}

resource.Test(t, resource.TestCase{
Expand Down
11 changes: 6 additions & 5 deletions internal/provider/organization_data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"testing"
"text/template"

"github.com/coder/coder/v2/coderd/util/ptr"
"github.com/coder/coder/v2/codersdk"
"github.com/coder/terraform-provider-coderd/integration"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
Expand Down Expand Up @@ -37,7 +38,7 @@ func TestAccOrganizationDataSource(t *testing.T) {
cfg := testAccOrganizationDataSourceConfig{
URL: client.URL.String(),
Token: client.SessionToken(),
ID: PtrTo(firstUser.OrganizationIDs[0].String()),
ID: ptr.Ref(firstUser.OrganizationIDs[0].String()),
}
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand All @@ -55,7 +56,7 @@ func TestAccOrganizationDataSource(t *testing.T) {
cfg := testAccOrganizationDataSourceConfig{
URL: client.URL.String(),
Token: client.SessionToken(),
Name: PtrTo("coder"),
Name: ptr.Ref("coder"),
}
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand All @@ -73,7 +74,7 @@ func TestAccOrganizationDataSource(t *testing.T) {
cfg := testAccOrganizationDataSourceConfig{
URL: client.URL.String(),
Token: client.SessionToken(),
IsDefault: PtrTo(true),
IsDefault: ptr.Ref(true),
}
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand All @@ -91,8 +92,8 @@ func TestAccOrganizationDataSource(t *testing.T) {
cfg := testAccOrganizationDataSourceConfig{
URL: client.URL.String(),
Token: client.SessionToken(),
IsDefault: PtrTo(true),
Name: PtrTo("coder"),
IsDefault: ptr.Ref(true),
Name: ptr.Ref("coder"),
}
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Expand Down
29 changes: 15 additions & 14 deletions internal/provider/template_data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/stretchr/testify/require"

"github.com/coder/coder/v2/coderd/util/ptr"
"github.com/coder/coder/v2/codersdk"
"github.com/coder/terraform-provider-coderd/integration"
)
Expand Down Expand Up @@ -49,21 +50,21 @@ func TestAccTemplateDataSource(t *testing.T) {
Description: "An example template",
Icon: "/path/to/icon.png",
VersionID: version.ID,
DefaultTTLMillis: PtrTo((10 * time.Hour).Milliseconds()),
ActivityBumpMillis: PtrTo((4 * time.Hour).Milliseconds()),
DefaultTTLMillis: ptr.Ref((10 * time.Hour).Milliseconds()),
ActivityBumpMillis: ptr.Ref((4 * time.Hour).Milliseconds()),
AutostopRequirement: &codersdk.TemplateAutostopRequirement{
DaysOfWeek: []string{"sunday"},
Weeks: 1,
},
AutostartRequirement: &codersdk.TemplateAutostartRequirement{
DaysOfWeek: []string{"monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"},
},
AllowUserCancelWorkspaceJobs: PtrTo(true),
AllowUserAutostart: PtrTo(true),
AllowUserAutostop: PtrTo(true),
FailureTTLMillis: PtrTo((1 * time.Hour).Milliseconds()),
TimeTilDormantMillis: PtrTo((7 * 24 * time.Hour).Milliseconds()),
TimeTilDormantAutoDeleteMillis: PtrTo((30 * 24 * time.Hour).Milliseconds()),
AllowUserCancelWorkspaceJobs: ptr.Ref(true),
AllowUserAutostart: ptr.Ref(true),
AllowUserAutostop: ptr.Ref(true),
FailureTTLMillis: ptr.Ref((1 * time.Hour).Milliseconds()),
TimeTilDormantMillis: ptr.Ref((7 * 24 * time.Hour).Milliseconds()),
TimeTilDormantAutoDeleteMillis: ptr.Ref((30 * 24 * time.Hour).Milliseconds()),
DisableEveryoneGroupAccess: true,
RequireActiveVersion: true,
})
Expand Down Expand Up @@ -93,9 +94,9 @@ func TestAccTemplateDataSource(t *testing.T) {
UpdateWorkspaceLastUsedAt: false,
UpdateWorkspaceDormantAt: false,
RequireActiveVersion: tpl.RequireActiveVersion,
DeprecationMessage: PtrTo("This template is deprecated"),
DeprecationMessage: ptr.Ref("This template is deprecated"),
DisableEveryoneGroupAccess: true,
MaxPortShareLevel: PtrTo(codersdk.WorkspaceAgentPortShareLevelOwner),
MaxPortShareLevel: ptr.Ref(codersdk.WorkspaceAgentPortShareLevelOwner),
})
require.NoError(t, err)

Expand Down Expand Up @@ -153,8 +154,8 @@ func TestAccTemplateDataSource(t *testing.T) {
cfg := testAccTemplateDataSourceConfig{
URL: client.URL.String(),
Token: client.SessionToken(),
OrganizationID: PtrTo(orgID.String()),
Name: PtrTo(tpl.Name),
OrganizationID: ptr.Ref(orgID.String()),
Name: ptr.Ref(tpl.Name),
}
resource.Test(t, resource.TestCase{
IsUnitTest: true,
Expand All @@ -173,7 +174,7 @@ func TestAccTemplateDataSource(t *testing.T) {
cfg := testAccTemplateDataSourceConfig{
URL: client.URL.String(),
Token: client.SessionToken(),
ID: PtrTo(tpl.ID.String()),
ID: ptr.Ref(tpl.ID.String()),
}
resource.Test(t, resource.TestCase{
IsUnitTest: true,
Expand Down Expand Up @@ -210,7 +211,7 @@ func TestAccTemplateDataSource(t *testing.T) {
cfg := testAccTemplateDataSourceConfig{
URL: client.URL.String(),
Token: client.SessionToken(),
Name: PtrTo(tpl.Name),
Name: ptr.Ref(tpl.Name),
}
resource.Test(t, resource.TestCase{
IsUnitTest: true,
Expand Down
3 changes: 2 additions & 1 deletion internal/provider/template_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"strings"

"cdr.dev/slog"
"github.com/coder/coder/v2/coderd/util/ptr"
"github.com/coder/coder/v2/codersdk"
"github.com/coder/coder/v2/provisionersdk"
"github.com/google/uuid"
Expand Down Expand Up @@ -1253,7 +1254,7 @@ func (r *TemplateResourceModel) toUpdateRequest(ctx context.Context, diag *diag.
TimeTilDormantAutoDeleteMillis: r.TimeTilDormantAutoDeleteMillis.ValueInt64(),
RequireActiveVersion: r.RequireActiveVersion.ValueBool(),
DeprecationMessage: r.DeprecationMessage.ValueStringPointer(),
MaxPortShareLevel: PtrTo(codersdk.WorkspaceAgentPortShareLevel(r.MaxPortShareLevel.ValueString())),
MaxPortShareLevel: ptr.Ref(codersdk.WorkspaceAgentPortShareLevel(r.MaxPortShareLevel.ValueString())),
// If we're managing ACL, we want to delete the everyone group
DisableEveryoneGroupAccess: !r.ACL.IsNull(),
}
Expand Down
Loading
Loading