Skip to content

Commit

Permalink
stacks: add includes for stack read and list
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielMSchmidt committed Aug 20, 2024
1 parent 6ad8729 commit 95a58ca
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
27 changes: 21 additions & 6 deletions stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type Stacks interface {
List(ctx context.Context, organization string, options *StackListOptions) (*StackList, error)

// Read returns a stack by its ID.
Read(ctx context.Context, stackID string) (*Stack, error)
Read(ctx context.Context, stackID string, options *StackReadOptions) (*Stack, error)

// Create creates a new stack.
Create(ctx context.Context, options StackCreateOptions) (*Stack, error)
Expand Down Expand Up @@ -143,12 +143,27 @@ type StackState struct {
ID string `jsonapi:"primary,stack-states"`
}

// StackIncludeOpt represents the include options for a stack.
type StackIncludeOpt string

const (
StackIncludeOrganization StackIncludeOpt = "organization"
StackIncludeProject StackIncludeOpt = "project"
StackIncludeLatestStackConfiguration StackIncludeOpt = "latest_stack_configuration"
StackIncludeStackDiagnostics StackIncludeOpt = "stack_diagnostics"
)

// StackListOptions represents the options for listing stacks.
type StackListOptions struct {
ListOptions
ProjectID string `url:"filter[project[id]],omitempty"`
Sort StackSortColumn `url:"sort,omitempty"`
SearchByName string `url:"search[name],omitempty"`
ProjectID string `url:"filter[project[id]],omitempty"`
Sort StackSortColumn `url:"sort,omitempty"`
SearchByName string `url:"search[name],omitempty"`
Include []StackIncludeOpt `url:"include,omitempty"`
}

type StackReadOptions struct {
Include []StackIncludeOpt `url:"include,omitempty"`
}

// StackCreateOptions represents the options for creating a stack. The project
Expand Down Expand Up @@ -221,8 +236,8 @@ func (s stacks) List(ctx context.Context, organization string, options *StackLis
}

// Read returns a stack by its ID.
func (s stacks) Read(ctx context.Context, stackID string) (*Stack, error) {
req, err := s.client.NewRequest("GET", fmt.Sprintf("stacks/%s", url.PathEscape(stackID)), nil)
func (s stacks) Read(ctx context.Context, stackID string, options *StackReadOptions) (*Stack, error) {
req, err := s.client.NewRequest("GET", fmt.Sprintf("stacks/%s", url.PathEscape(stackID)), options)
if err != nil {
return nil, err
}
Expand Down
6 changes: 3 additions & 3 deletions stack_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func TestStackReadUpdateDelete(t *testing.T) {
require.NoError(t, err)
require.NotNil(t, stack)

stackRead, err := client.Stacks.Read(ctx, stack.ID)
stackRead, err := client.Stacks.Read(ctx, stack.ID, nil)
require.NoError(t, err)

assert.Equal(t, stack, stackRead)
Expand All @@ -174,7 +174,7 @@ func TestStackReadUpdateDelete(t *testing.T) {
err = client.Stacks.Delete(ctx, stack.ID)
require.NoError(t, err)

stackReadAfterDelete, err := client.Stacks.Read(ctx, stack.ID)
stackReadAfterDelete, err := client.Stacks.Read(ctx, stack.ID, nil)
require.ErrorIs(t, err, ErrResourceNotFound)
require.Nil(t, stackReadAfterDelete)
}
Expand All @@ -199,7 +199,7 @@ func pollStackDeployments(t *testing.T, ctx context.Context, client *Client, sta
t.Fatalf("Stack %q had no deployments at deadline", stackID)
case <-ticker.C:
var err error
stack, err = client.Stacks.Read(ctx, stackID)
stack, err = client.Stacks.Read(ctx, stackID, nil)
if err != nil {
t.Fatalf("Failed to read stack %q: %s", stackID, err)
}
Expand Down

0 comments on commit 95a58ca

Please sign in to comment.