Skip to content
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

fix(stacks/vcs): StackVCSRepo nested-struct incorrectly serializing attributes #1029

Merged
merged 3 commits into from
Jan 13, 2025
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
20 changes: 14 additions & 6 deletions stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ type StackVCSRepo struct {
OAuthTokenID string `jsonapi:"attr,oauth-token-id,omitempty"`
}

// StackVCSRepoOptions
type StackVCSRepoOptions struct {
Identifier string `json:"identifier"`
Branch string `json:"branch,omitempty"`
GHAInstallationID string `json:"github-app-installation-id,omitempty"`
OAuthTokenID string `json:"oauth-token-id,omitempty"`
}

// Stack represents a stack.
type Stack struct {
ID string `jsonapi:"primary,stacks"`
Expand Down Expand Up @@ -172,11 +180,11 @@ type StackReadOptions struct {
// StackCreateOptions represents the options for creating a stack. The project
// relation is required.
type StackCreateOptions struct {
Type string `jsonapi:"primary,stacks"`
Name string `jsonapi:"attr,name"`
Description *string `jsonapi:"attr,description,omitempty"`
VCSRepo *StackVCSRepo `jsonapi:"attr,vcs-repo"`
Project *Project `jsonapi:"relation,project"`
Type string `jsonapi:"primary,stacks"`
Name string `jsonapi:"attr,name"`
Description *string `jsonapi:"attr,description,omitempty"`
VCSRepo *StackVCSRepoOptions `jsonapi:"attr,vcs-repo"`
Project *Project `jsonapi:"relation,project"`
}

// StackUpdateOptions represents the options for updating a stack.
Expand Down Expand Up @@ -326,7 +334,7 @@ func (s StackCreateOptions) valid() error {
return s.VCSRepo.valid()
}

func (s StackVCSRepo) valid() error {
func (s StackVCSRepoOptions) valid() error {
if s.Identifier == "" {
return ErrRequiredVCSRepo
}
Expand Down
10 changes: 5 additions & 5 deletions stack_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestStackCreateAndList(t *testing.T) {

stack1, err := client.Stacks.Create(ctx, StackCreateOptions{
Name: "aa-test-stack",
VCSRepo: &StackVCSRepo{
VCSRepo: &StackVCSRepoOptions{
Identifier: "hashicorp-guides/pet-nulls-stack",
OAuthTokenID: oauthClient.OAuthTokens[0].ID,
},
Expand All @@ -45,7 +45,7 @@ func TestStackCreateAndList(t *testing.T) {

stack2, err := client.Stacks.Create(ctx, StackCreateOptions{
Name: "zz-test-stack",
VCSRepo: &StackVCSRepo{
VCSRepo: &StackVCSRepoOptions{
Identifier: "hashicorp-guides/pet-nulls-stack",
OAuthTokenID: oauthClient.OAuthTokens[0].ID,
},
Expand Down Expand Up @@ -143,7 +143,7 @@ func TestStackReadUpdateDelete(t *testing.T) {

stack, err := client.Stacks.Create(ctx, StackCreateOptions{
Name: "test-stack",
VCSRepo: &StackVCSRepo{
VCSRepo: &StackVCSRepoOptions{
Identifier: "brandonc/pet-nulls-stack",
OAuthTokenID: oauthClient.OAuthTokens[0].ID,
Branch: "main",
Expand Down Expand Up @@ -200,7 +200,7 @@ func TestStackReadUpdateForceDelete(t *testing.T) {

stack, err := client.Stacks.Create(ctx, StackCreateOptions{
Name: "test-stack",
VCSRepo: &StackVCSRepo{
VCSRepo: &StackVCSRepoOptions{
Identifier: "brandonc/pet-nulls-stack",
OAuthTokenID: oauthClient.OAuthTokens[0].ID,
Branch: "main",
Expand Down Expand Up @@ -356,7 +356,7 @@ func TestStackConverged(t *testing.T) {

stack, err := client.Stacks.Create(ctx, StackCreateOptions{
Name: "test-stack",
VCSRepo: &StackVCSRepo{
VCSRepo: &StackVCSRepoOptions{
Identifier: "brandonc/pet-nulls-stack",
OAuthTokenID: oauthClient.OAuthTokens[0].ID,
},
Expand Down
2 changes: 1 addition & 1 deletion stack_plan_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestStackPlanList(t *testing.T) {

stack, err := client.Stacks.Create(ctx, StackCreateOptions{
Name: "aa-test-stack",
VCSRepo: &StackVCSRepo{
VCSRepo: &StackVCSRepoOptions{
Identifier: "brandonc/pet-nulls-stack",
OAuthTokenID: oauthClient.OAuthTokens[0].ID,
},
Expand Down
2 changes: 1 addition & 1 deletion stack_source_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestStackSourceCreateUploadAndRead(t *testing.T) {
stack, err := client.Stacks.Create(ctx, StackCreateOptions{
Project: orgTest.DefaultProject,
Name: "test-stack",
VCSRepo: &StackVCSRepo{
VCSRepo: &StackVCSRepoOptions{
Identifier: "hashicorp-guides/pet-nulls-stack",
OAuthTokenID: oauthClient.OAuthTokens[0].ID,
},
Expand Down
Loading