Skip to content

Commit

Permalink
fix: separate request/response annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
mjyocca committed Jan 10, 2025
1 parent 208cd52 commit 305f2d7
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 12 deletions.
26 changes: 21 additions & 5 deletions stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,14 @@ type StackList struct {

// StackVCSRepo represents the version control system repository for a stack.
type StackVCSRepo struct {
Identifier string `jsonapi:"attr,identifier"`
Branch string `jsonapi:"attr,branch,omitempty"`
GHAInstallationID string `jsonapi:"attr,github-app-installation-id,omitempty"`
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"`
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 @@ -334,6 +342,14 @@ func (s StackVCSRepo) valid() error {
return nil
}

func (s StackVCSRepoOptions) valid() error {
if s.Identifier == "" {
return ErrRequiredVCSRepo
}

return nil
}

// awaitPoll is a helper function that uses a callback to read a status, then
// waits for a terminal status or an error. The callback should return the
// current status, or an error. For each time the status changes, the channel
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

0 comments on commit 305f2d7

Please sign in to comment.