Skip to content

Commit 6621d45

Browse files
committed
use one ToolVersionArchitecture struct
1 parent d7b119f commit 6621d45

File tree

2 files changed

+47
-35
lines changed

2 files changed

+47
-35
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: 27 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)
@@ -275,20 +273,41 @@ func TestAdminTerraformVersions_ReadUpdate(t *testing.T) {
275273
})
276274

277275
t.Run("update with Archs", func(t *testing.T) {
278-
updateVersion := genSafeRandomTerraformVersion()
276+
version := genSafeRandomTerraformVersion()
279277
sha := String(genSha(t))
278+
opts := AdminTerraformVersionCreateOptions{
279+
Version: String(version),
280+
URL: String("https://www.hashicorp.com"),
281+
Sha: String(genSha(t)),
282+
Official: Bool(false),
283+
Deprecated: Bool(true),
284+
DeprecatedReason: String("Test Reason"),
285+
Enabled: Bool(false),
286+
Beta: Bool(false),
287+
Archs: []*ToolVersionArchitecture{{
288+
URL: "https://www.hashicorp.com",
289+
Sha: *sha,
290+
OS: linux,
291+
Arch: amd64,
292+
}},
293+
}
294+
tfv, err := client.Admin.TerraformVersions.Create(ctx, opts)
295+
require.NoError(t, err)
296+
id := tfv.ID
297+
298+
updateVersion := genSafeRandomTerraformVersion()
280299
updateArchOpts := AdminTerraformVersionUpdateOptions{
281300
Version: String(updateVersion),
282301
Deprecated: Bool(false),
283-
Archs: []*ToolVersionArchitectureOptions{{
302+
Archs: []*ToolVersionArchitecture{{
284303
URL: "https://www.hashicorp.com",
285304
Sha: *sha,
286305
OS: linux,
287306
Arch: amd64,
288307
}},
289308
}
290309

291-
tfv, err := client.Admin.TerraformVersions.Update(ctx, id, updateArchOpts)
310+
tfv, err = client.Admin.TerraformVersions.Update(ctx, id, updateArchOpts)
292311
require.NoError(t, err)
293312

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

0 commit comments

Comments
 (0)