Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Unreleased

## Bug Fixes

Fix an issue where stack creation panics if no project is provided in the `StackCreateOptions` creation options structure by @arybolovlev [#1284](https://github.com/hashicorp/go-tfe/pull/1284)

# v1.101.0

## Enhancements
Expand Down
2 changes: 1 addition & 1 deletion stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ func (s StackCreateOptions) valid() error {
return ErrRequiredName
}

if s.Project.ID == "" {
if s.Project == nil || s.Project.ID == "" {
return ErrRequiredProject
}

Expand Down
52 changes: 52 additions & 0 deletions stack_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright IBM Corp. 2018, 2025
// SPDX-License-Identifier: MPL-2.0

package tfe

import (
"testing"

"github.com/stretchr/testify/assert"
)

func Test_validStackCreateOptions(t *testing.T) {
t.Parallel()

t.Run("with empty stack name", func(t *testing.T) {
s := &StackCreateOptions{
Name: "",
}
err := s.valid()
assert.Error(t, err, ErrRequiredName.Error())
})

t.Run("with empty project option", func(t *testing.T) {
s := &StackCreateOptions{
Name: "test",
}
err := s.valid()
assert.Error(t, err, ErrRequiredProject.Error())
})

t.Run("with empty project ID", func(t *testing.T) {
s := &StackCreateOptions{
Name: "test",
Project: &Project{
ID: "",
},
}
err := s.valid()
assert.Error(t, err, ErrRequiredProject.Error())
})

t.Run("with valid options", func(t *testing.T) {
s := &StackCreateOptions{
Name: "test",
Project: &Project{
ID: "prj-test",
},
}
err := s.valid()
assert.NoError(t, err)
})
}
Loading