Skip to content

Commit 4397429

Browse files
committed
update jsonapi 1.4.1, use 1 ToolVersionArchitecture struct
1 parent ec4629b commit 4397429

File tree

4 files changed

+56
-38
lines changed

4 files changed

+56
-38
lines changed

admin_terraform_version.go

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,6 @@ type ToolVersionArchitecture struct {
7070
Arch string `jsonapi:"attr,arch"`
7171
}
7272

73-
type ToolVersionArchitectureOptions struct {
74-
URL string `json:"url"`
75-
Sha string `json:"sha"`
76-
OS string `json:"os"`
77-
Arch string `json:"arch"`
78-
}
79-
8073
// AdminTerraformVersionsListOptions represents the options for listing
8174
// terraform versions.
8275
type AdminTerraformVersionsListOptions struct {
@@ -92,31 +85,31 @@ type AdminTerraformVersionsListOptions struct {
9285
// AdminTerraformVersionCreateOptions for creating a terraform version.
9386
// https://developer.hashicorp.com/terraform/enterprise/api-docs/admin/terraform-versions#request-body
9487
type AdminTerraformVersionCreateOptions struct {
95-
Type string `jsonapi:"primary,terraform-versions"`
96-
Version *string `jsonapi:"attr,version"` // Required
97-
URL *string `jsonapi:"attr,url,omitempty"`
98-
Sha *string `jsonapi:"attr,sha,omitempty"`
99-
Official *bool `jsonapi:"attr,official,omitempty"`
100-
Deprecated *bool `jsonapi:"attr,deprecated,omitempty"`
101-
DeprecatedReason *string `jsonapi:"attr,deprecated-reason,omitempty"`
102-
Enabled *bool `jsonapi:"attr,enabled,omitempty"`
103-
Beta *bool `jsonapi:"attr,beta,omitempty"`
104-
Archs []*ToolVersionArchitectureOptions `jsonapi:"attr,archs,omitempty"`
88+
Type string `jsonapi:"primary,terraform-versions"`
89+
Version *string `jsonapi:"attr,version"` // Required
90+
URL *string `jsonapi:"attr,url,omitempty"`
91+
Sha *string `jsonapi:"attr,sha,omitempty"`
92+
Official *bool `jsonapi:"attr,official,omitempty"`
93+
Deprecated *bool `jsonapi:"attr,deprecated,omitempty"`
94+
DeprecatedReason *string `jsonapi:"attr,deprecated-reason,omitempty"`
95+
Enabled *bool `jsonapi:"attr,enabled,omitempty"`
96+
Beta *bool `jsonapi:"attr,beta,omitempty"`
97+
Archs []*ToolVersionArchitecture `jsonapi:"attr,archs,omitempty"`
10598
}
10699

107100
// AdminTerraformVersionUpdateOptions for updating terraform version.
108101
// https://developer.hashicorp.com/terraform/enterprise/api-docs/admin/terraform-versions#request-body
109102
type AdminTerraformVersionUpdateOptions struct {
110-
Type string `jsonapi:"primary,terraform-versions"`
111-
Version *string `jsonapi:"attr,version,omitempty"`
112-
URL *string `jsonapi:"attr,url,omitempty"`
113-
Sha *string `jsonapi:"attr,sha,omitempty"`
114-
Official *bool `jsonapi:"attr,official,omitempty"`
115-
Deprecated *bool `jsonapi:"attr,deprecated,omitempty"`
116-
DeprecatedReason *string `jsonapi:"attr,deprecated-reason,omitempty"`
117-
Enabled *bool `jsonapi:"attr,enabled,omitempty"`
118-
Beta *bool `jsonapi:"attr,beta,omitempty"`
119-
Archs []*ToolVersionArchitectureOptions `jsonapi:"attr,archs,omitempty"`
103+
Type string `jsonapi:"primary,terraform-versions"`
104+
Version *string `jsonapi:"attr,version,omitempty"`
105+
URL *string `jsonapi:"attr,url,omitempty"`
106+
Sha *string `jsonapi:"attr,sha,omitempty"`
107+
Official *bool `jsonapi:"attr,official,omitempty"`
108+
Deprecated *bool `jsonapi:"attr,deprecated,omitempty"`
109+
DeprecatedReason *string `jsonapi:"attr,deprecated-reason,omitempty"`
110+
Enabled *bool `jsonapi:"attr,enabled,omitempty"`
111+
Beta *bool `jsonapi:"attr,beta,omitempty"`
112+
Archs []*ToolVersionArchitecture `jsonapi:"attr,archs,omitempty"`
120113
}
121114

122115
// AdminTerraformVersionsList represents a list of terraform versions.

admin_terraform_version_integration_test.go

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func TestAdminTerraformVersions_CreateDelete(t *testing.T) {
109109
Official: Bool(false),
110110
Enabled: Bool(false),
111111
Beta: Bool(false),
112-
Archs: []*ToolVersionArchitectureOptions{
112+
Archs: []*ToolVersionArchitecture{
113113
{
114114
URL: "https://www.hashicorp.com",
115115
Sha: *String(genSha(t)),
@@ -212,8 +212,6 @@ func TestAdminTerraformVersions_ReadUpdate(t *testing.T) {
212212
client := testClient(t)
213213
ctx := context.Background()
214214

215-
var id string
216-
217215
t.Run("reads and updates", func(t *testing.T) {
218216
version := genSafeRandomTerraformVersion()
219217
sha := String(genSha(t))
@@ -226,7 +224,7 @@ func TestAdminTerraformVersions_ReadUpdate(t *testing.T) {
226224
DeprecatedReason: String("Test Reason"),
227225
Enabled: Bool(false),
228226
Beta: Bool(false),
229-
Archs: []*ToolVersionArchitectureOptions{{
227+
Archs: []*ToolVersionArchitecture{{
230228
URL: "https://www.hashicorp.com",
231229
Sha: *sha,
232230
OS: linux,
@@ -235,7 +233,7 @@ func TestAdminTerraformVersions_ReadUpdate(t *testing.T) {
235233
}
236234
tfv, err := client.Admin.TerraformVersions.Create(ctx, opts)
237235
require.NoError(t, err)
238-
id = tfv.ID
236+
id := tfv.ID
239237

240238
defer func() {
241239
deleteErr := client.Admin.TerraformVersions.Delete(ctx, id)
@@ -263,6 +261,7 @@ func TestAdminTerraformVersions_ReadUpdate(t *testing.T) {
263261
}
264262

265263
tfv, err = client.Admin.TerraformVersions.Update(ctx, id, updateOpts)
264+
266265
require.NoError(t, err)
267266

268267
assert.Equal(t, updateVersion, tfv.Version)
@@ -275,20 +274,46 @@ func TestAdminTerraformVersions_ReadUpdate(t *testing.T) {
275274
})
276275

277276
t.Run("update with Archs", func(t *testing.T) {
278-
updateVersion := genSafeRandomTerraformVersion()
277+
version := genSafeRandomTerraformVersion()
279278
sha := String(genSha(t))
279+
opts := AdminTerraformVersionCreateOptions{
280+
Version: String(version),
281+
URL: String("https://www.hashicorp.com"),
282+
Sha: String(genSha(t)),
283+
Official: Bool(false),
284+
Deprecated: Bool(true),
285+
DeprecatedReason: String("Test Reason"),
286+
Enabled: Bool(false),
287+
Beta: Bool(false),
288+
Archs: []*ToolVersionArchitecture{{
289+
URL: "https://www.hashicorp.com",
290+
Sha: *sha,
291+
OS: linux,
292+
Arch: amd64,
293+
}},
294+
}
295+
tfv, err := client.Admin.TerraformVersions.Create(ctx, opts)
296+
require.NoError(t, err)
297+
id := tfv.ID
298+
299+
defer func() {
300+
deleteErr := client.Admin.TerraformVersions.Delete(ctx, id)
301+
require.NoError(t, deleteErr)
302+
}()
303+
304+
updateVersion := genSafeRandomTerraformVersion()
280305
updateArchOpts := AdminTerraformVersionUpdateOptions{
281306
Version: String(updateVersion),
282307
Deprecated: Bool(false),
283-
Archs: []*ToolVersionArchitectureOptions{{
308+
Archs: []*ToolVersionArchitecture{{
284309
URL: "https://www.hashicorp.com",
285310
Sha: *sha,
286311
OS: linux,
287312
Arch: amd64,
288313
}},
289314
}
290315

291-
tfv, err := client.Admin.TerraformVersions.Update(ctx, id, updateArchOpts)
316+
tfv, err = client.Admin.TerraformVersions.Update(ctx, id, updateArchOpts)
292317
require.NoError(t, err)
293318

294319
assert.Equal(t, len(tfv.Archs), 1)

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ require (
99
github.com/hashicorp/go-slug v0.16.4
1010
github.com/hashicorp/go-uuid v1.0.3
1111
github.com/hashicorp/go-version v1.7.0
12-
github.com/hashicorp/jsonapi v1.3.2
12+
github.com/hashicorp/jsonapi v1.4.1
1313
github.com/stretchr/testify v1.10.0
1414
go.uber.org/mock v0.4.0
1515
golang.org/x/sync v0.10.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ github.com/hashicorp/go-uuid v1.0.3 h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/C
1616
github.com/hashicorp/go-uuid v1.0.3/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
1717
github.com/hashicorp/go-version v1.7.0 h1:5tqGy27NaOTB8yJKUZELlFAS/LTKJkrmONwQKeRZfjY=
1818
github.com/hashicorp/go-version v1.7.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
19-
github.com/hashicorp/jsonapi v1.3.2 h1:gP3fX2ZT7qXi+PbwieptzkspIohO2kCSiBUvUTBAbMs=
20-
github.com/hashicorp/jsonapi v1.3.2/go.mod h1:kWfdn49yCjQvbpnvY1dxxAuAFzISwrrMDQOcu6NsFoM=
19+
github.com/hashicorp/jsonapi v1.4.1 h1:U6CZvnS70Sg7im0kpfhWAoF3NasLumaMndQhEWniHZA=
20+
github.com/hashicorp/jsonapi v1.4.1/go.mod h1:kWfdn49yCjQvbpnvY1dxxAuAFzISwrrMDQOcu6NsFoM=
2121
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
2222
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
2323
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=

0 commit comments

Comments
 (0)