Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3890c2d

Browse files
committed
useptr.Ref
1 parent6370ad3 commit3890c2d

14 files changed

+139
-136
lines changed

‎.golangci.yml‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# Visit https://golangci-lint.run/ for usage documentation
2-
#and information onother useful linters
1+
# Visit https://golangci-lint.run/ for usage documentation and information on
2+
# other useful linters
33
issues:
44
max-per-linter:0
55
max-same-issues:0
@@ -24,4 +24,4 @@ linters:
2424
-unconvert
2525
-unparam
2626
-unused
27-
-vet
27+
-vet

‎internal/provider/group_data_source_test.go‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"testing"
99
"text/template"
1010

11+
"github.com/coder/coder/v2/coderd/util/ptr"
1112
"github.com/coder/coder/v2/codersdk"
1213
"github.com/coder/terraform-provider-coderd/integration"
1314
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
@@ -74,7 +75,7 @@ func TestAccGroupDataSource(t *testing.T) {
7475
cfg:=testAccGroupDataSourceConfig{
7576
URL:client.URL.String(),
7677
Token:client.SessionToken(),
77-
ID:PtrTo(group.ID.String()),
78+
ID:ptr.Ref(group.ID.String()),
7879
}
7980
resource.Test(t, resource.TestCase{
8081
PreCheck:func() {testAccPreCheck(t) },
@@ -92,8 +93,8 @@ func TestAccGroupDataSource(t *testing.T) {
9293
cfg:=testAccGroupDataSourceConfig{
9394
URL:client.URL.String(),
9495
Token:client.SessionToken(),
95-
OrganizationID:PtrTo(firstUser.OrganizationIDs[0].String()),
96-
Name:PtrTo("example-group"),
96+
OrganizationID:ptr.Ref(firstUser.OrganizationIDs[0].String()),
97+
Name:ptr.Ref("example-group"),
9798
}
9899
resource.Test(t, resource.TestCase{
99100
PreCheck:func() {testAccPreCheck(t) },
@@ -111,7 +112,7 @@ func TestAccGroupDataSource(t *testing.T) {
111112
cfg:=testAccGroupDataSourceConfig{
112113
URL:client.URL.String(),
113114
Token:client.SessionToken(),
114-
Name:PtrTo("example-group"),
115+
Name:ptr.Ref("example-group"),
115116
}
116117
resource.Test(t, resource.TestCase{
117118
PreCheck:func() {testAccPreCheck(t) },
@@ -129,7 +130,7 @@ func TestAccGroupDataSource(t *testing.T) {
129130
cfg:=testAccGroupDataSourceConfig{
130131
URL:client.URL.String(),
131132
Token:client.SessionToken(),
132-
OrganizationID:PtrTo(firstUser.OrganizationIDs[0].String()),
133+
OrganizationID:ptr.Ref(firstUser.OrganizationIDs[0].String()),
133134
}
134135
resource.Test(t, resource.TestCase{
135136
PreCheck:func() {testAccPreCheck(t) },
@@ -187,7 +188,7 @@ data "coderd_group" "test" {
187188
`
188189

189190
funcMap:= template.FuncMap{
190-
"orNull":PrintOrNull,
191+
"orNull":printOrNull,
191192
}
192193

193194
buf:= strings.Builder{}

‎internal/provider/group_resource.go‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,8 @@ func (r *GroupResource) Configure(ctx context.Context, req resource.ConfigureReq
143143
}
144144

145145
func (r*GroupResource)Create(ctx context.Context,req resource.CreateRequest,resp*resource.CreateResponse) {
146-
vardataGroupResourceModel
147-
148146
// Read Terraform plan data into the model
147+
vardataGroupResourceModel
149148
resp.Diagnostics.Append(req.Plan.Get(ctx,&data)...)
150149

151150
ifresp.Diagnostics.HasError() {

‎internal/provider/group_resource_test.go‎

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"testing"
99
"text/template"
1010

11+
"github.com/coder/coder/v2/coderd/util/ptr"
1112
"github.com/coder/coder/v2/codersdk"
1213
"github.com/coder/terraform-provider-coderd/integration"
1314
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
@@ -44,17 +45,17 @@ func TestAccGroupResource(t *testing.T) {
4445
cfg1:=testAccGroupResourceconfig{
4546
URL:client.URL.String(),
4647
Token:client.SessionToken(),
47-
Name:PtrTo("example-group"),
48-
DisplayName:PtrTo("Example Group"),
49-
AvatarUrl:PtrTo("https://google.com"),
50-
QuotaAllowance:PtrTo(int32(100)),
51-
Members:PtrTo([]string{user1.ID.String()}),
48+
Name:ptr.Ref("example-group"),
49+
DisplayName:ptr.Ref("Example Group"),
50+
AvatarUrl:ptr.Ref("https://google.com"),
51+
QuotaAllowance:ptr.Ref(int32(100)),
52+
Members:ptr.Ref([]string{user1.ID.String()}),
5253
}
5354

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

5960
cfg3:=cfg2
6061
cfg3.Members=nil
@@ -143,11 +144,11 @@ func TestAccGroupResourceAGPL(t *testing.T) {
143144
cfg1:=testAccGroupResourceconfig{
144145
URL:client.URL.String(),
145146
Token:client.SessionToken(),
146-
Name:PtrTo("example-group"),
147-
DisplayName:PtrTo("Example Group"),
148-
AvatarUrl:PtrTo("https://google.com"),
149-
QuotaAllowance:PtrTo(int32(100)),
150-
Members:PtrTo([]string{firstUser.ID.String()}),
147+
Name:ptr.Ref("example-group"),
148+
DisplayName:ptr.Ref("Example Group"),
149+
AvatarUrl:ptr.Ref("https://google.com"),
150+
QuotaAllowance:ptr.Ref(int32(100)),
151+
Members:ptr.Ref([]string{firstUser.ID.String()}),
151152
}
152153

153154
resource.Test(t, resource.TestCase{
@@ -194,7 +195,7 @@ resource "coderd_group" "test" {
194195
}
195196
`
196197
funcMap:= template.FuncMap{
197-
"orNull":PrintOrNull,
198+
"orNull":printOrNull,
198199
}
199200

200201
buf:= strings.Builder{}

‎internal/provider/license_resource_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ resource "coderd_license" "test" {
6161
}
6262
`
6363
funcMap:= template.FuncMap{
64-
"orNull":PrintOrNull,
64+
"orNull":printOrNull,
6565
}
6666

6767
buf:= strings.Builder{}

‎internal/provider/organization_data_source_test.go‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"testing"
99
"text/template"
1010

11+
"github.com/coder/coder/v2/coderd/util/ptr"
1112
"github.com/coder/coder/v2/codersdk"
1213
"github.com/coder/terraform-provider-coderd/integration"
1314
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
@@ -37,7 +38,7 @@ func TestAccOrganizationDataSource(t *testing.T) {
3738
cfg:=testAccOrganizationDataSourceConfig{
3839
URL:client.URL.String(),
3940
Token:client.SessionToken(),
40-
ID:PtrTo(firstUser.OrganizationIDs[0].String()),
41+
ID:ptr.Ref(firstUser.OrganizationIDs[0].String()),
4142
}
4243
resource.Test(t, resource.TestCase{
4344
PreCheck:func() {testAccPreCheck(t) },
@@ -55,7 +56,7 @@ func TestAccOrganizationDataSource(t *testing.T) {
5556
cfg:=testAccOrganizationDataSourceConfig{
5657
URL:client.URL.String(),
5758
Token:client.SessionToken(),
58-
Name:PtrTo("coder"),
59+
Name:ptr.Ref("coder"),
5960
}
6061
resource.Test(t, resource.TestCase{
6162
PreCheck:func() {testAccPreCheck(t) },
@@ -73,7 +74,7 @@ func TestAccOrganizationDataSource(t *testing.T) {
7374
cfg:=testAccOrganizationDataSourceConfig{
7475
URL:client.URL.String(),
7576
Token:client.SessionToken(),
76-
IsDefault:PtrTo(true),
77+
IsDefault:ptr.Ref(true),
7778
}
7879
resource.Test(t, resource.TestCase{
7980
PreCheck:func() {testAccPreCheck(t) },
@@ -91,8 +92,8 @@ func TestAccOrganizationDataSource(t *testing.T) {
9192
cfg:=testAccOrganizationDataSourceConfig{
9293
URL:client.URL.String(),
9394
Token:client.SessionToken(),
94-
IsDefault:PtrTo(true),
95-
Name:PtrTo("coder"),
95+
IsDefault:ptr.Ref(true),
96+
Name:ptr.Ref("coder"),
9697
}
9798
resource.Test(t, resource.TestCase{
9899
PreCheck:func() {testAccPreCheck(t) },
@@ -133,7 +134,7 @@ data "coderd_organization" "test" {
133134
`
134135

135136
funcMap:= template.FuncMap{
136-
"orNull":PrintOrNull,
137+
"orNull":printOrNull,
137138
}
138139

139140
buf:= strings.Builder{}

‎internal/provider/provider.go‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ This provider is only compatible with Coder version [2.10.1](https://github.com/
7878

7979
func (p*CoderdProvider)Configure(ctx context.Context,req provider.ConfigureRequest,resp*provider.ConfigureResponse) {
8080
vardataCoderdProviderModel
81-
8281
resp.Diagnostics.Append(req.Config.Get(ctx,&data)...)
8382

8483
ifresp.Diagnostics.HasError() {

‎internal/provider/template_data_source_test.go‎

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
1515
"github.com/stretchr/testify/require"
1616

17+
"github.com/coder/coder/v2/coderd/util/ptr"
1718
"github.com/coder/coder/v2/codersdk"
1819
"github.com/coder/terraform-provider-coderd/integration"
1920
)
@@ -49,21 +50,21 @@ func TestAccTemplateDataSource(t *testing.T) {
4950
Description:"An example template",
5051
Icon:"/path/to/icon.png",
5152
VersionID:version.ID,
52-
DefaultTTLMillis:PtrTo((10*time.Hour).Milliseconds()),
53-
ActivityBumpMillis:PtrTo((4*time.Hour).Milliseconds()),
53+
DefaultTTLMillis:ptr.Ref((10*time.Hour).Milliseconds()),
54+
ActivityBumpMillis:ptr.Ref((4*time.Hour).Milliseconds()),
5455
AutostopRequirement:&codersdk.TemplateAutostopRequirement{
5556
DaysOfWeek: []string{"sunday"},
5657
Weeks:1,
5758
},
5859
AutostartRequirement:&codersdk.TemplateAutostartRequirement{
5960
DaysOfWeek: []string{"monday","tuesday","wednesday","thursday","friday","saturday","sunday"},
6061
},
61-
AllowUserCancelWorkspaceJobs:PtrTo(true),
62-
AllowUserAutostart:PtrTo(true),
63-
AllowUserAutostop:PtrTo(true),
64-
FailureTTLMillis:PtrTo((1*time.Hour).Milliseconds()),
65-
TimeTilDormantMillis:PtrTo((7*24*time.Hour).Milliseconds()),
66-
TimeTilDormantAutoDeleteMillis:PtrTo((30*24*time.Hour).Milliseconds()),
62+
AllowUserCancelWorkspaceJobs:ptr.Ref(true),
63+
AllowUserAutostart:ptr.Ref(true),
64+
AllowUserAutostop:ptr.Ref(true),
65+
FailureTTLMillis:ptr.Ref((1*time.Hour).Milliseconds()),
66+
TimeTilDormantMillis:ptr.Ref((7*24*time.Hour).Milliseconds()),
67+
TimeTilDormantAutoDeleteMillis:ptr.Ref((30*24*time.Hour).Milliseconds()),
6768
DisableEveryoneGroupAccess:true,
6869
RequireActiveVersion:true,
6970
})
@@ -93,9 +94,9 @@ func TestAccTemplateDataSource(t *testing.T) {
9394
UpdateWorkspaceLastUsedAt:false,
9495
UpdateWorkspaceDormantAt:false,
9596
RequireActiveVersion:tpl.RequireActiveVersion,
96-
DeprecationMessage:PtrTo("This template is deprecated"),
97+
DeprecationMessage:ptr.Ref("This template is deprecated"),
9798
DisableEveryoneGroupAccess:true,
98-
MaxPortShareLevel:PtrTo(codersdk.WorkspaceAgentPortShareLevelOwner),
99+
MaxPortShareLevel:ptr.Ref(codersdk.WorkspaceAgentPortShareLevelOwner),
99100
})
100101
require.NoError(t,err)
101102

@@ -153,8 +154,8 @@ func TestAccTemplateDataSource(t *testing.T) {
153154
cfg:=testAccTemplateDataSourceConfig{
154155
URL:client.URL.String(),
155156
Token:client.SessionToken(),
156-
OrganizationID:PtrTo(orgID.String()),
157-
Name:PtrTo(tpl.Name),
157+
OrganizationID:ptr.Ref(orgID.String()),
158+
Name:ptr.Ref(tpl.Name),
158159
}
159160
resource.Test(t, resource.TestCase{
160161
IsUnitTest:true,
@@ -173,7 +174,7 @@ func TestAccTemplateDataSource(t *testing.T) {
173174
cfg:=testAccTemplateDataSourceConfig{
174175
URL:client.URL.String(),
175176
Token:client.SessionToken(),
176-
ID:PtrTo(tpl.ID.String()),
177+
ID:ptr.Ref(tpl.ID.String()),
177178
}
178179
resource.Test(t, resource.TestCase{
179180
IsUnitTest:true,
@@ -210,7 +211,7 @@ func TestAccTemplateDataSource(t *testing.T) {
210211
cfg:=testAccTemplateDataSourceConfig{
211212
URL:client.URL.String(),
212213
Token:client.SessionToken(),
213-
Name:PtrTo(tpl.Name),
214+
Name:ptr.Ref(tpl.Name),
214215
}
215216
resource.Test(t, resource.TestCase{
216217
IsUnitTest:true,
@@ -250,7 +251,7 @@ data "coderd_template" "test" {
250251
}`
251252

252253
funcMap:= template.FuncMap{
253-
"orNull":PrintOrNull,
254+
"orNull":printOrNull,
254255
}
255256

256257
buf:= strings.Builder{}

‎internal/provider/template_resource.go‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"strings"
1111

1212
"cdr.dev/slog"
13+
"github.com/coder/coder/v2/coderd/util/ptr"
1314
"github.com/coder/coder/v2/codersdk"
1415
"github.com/coder/coder/v2/provisionersdk"
1516
"github.com/google/uuid"
@@ -1253,7 +1254,7 @@ func (r *TemplateResourceModel) toUpdateRequest(ctx context.Context, diag *diag.
12531254
TimeTilDormantAutoDeleteMillis:r.TimeTilDormantAutoDeleteMillis.ValueInt64(),
12541255
RequireActiveVersion:r.RequireActiveVersion.ValueBool(),
12551256
DeprecationMessage:r.DeprecationMessage.ValueStringPointer(),
1256-
MaxPortShareLevel:PtrTo(codersdk.WorkspaceAgentPortShareLevel(r.MaxPortShareLevel.ValueString())),
1257+
MaxPortShareLevel:ptr.Ref(codersdk.WorkspaceAgentPortShareLevel(r.MaxPortShareLevel.ValueString())),
12571258
// If we're managing ACL, we want to delete the everyone group
12581259
DisableEveryoneGroupAccess:!r.ACL.IsNull(),
12591260
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp