Skip to content

Commit

Permalink
Merge pull request #964 from hashicorp/brandonc/fix_vcsrepo_encoding
Browse files Browse the repository at this point in the history
Fix Stacks vcs-repo encoding
  • Loading branch information
brandonc authored Aug 23, 2024
2 parents 9be0628 + c93ac9d commit d0cc62d
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 5 deletions.
8 changes: 4 additions & 4 deletions stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ type StackList struct {

// StackVCSRepo represents the version control system repository for a stack.
type StackVCSRepo 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"`
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"`
}

// Stack represents a stack.
Expand Down
7 changes: 7 additions & 0 deletions stack_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ func TestStackReadUpdateDelete(t *testing.T) {
VCSRepo: &StackVCSRepo{
Identifier: "brandonc/pet-nulls-stack",
OAuthTokenID: oauthClient.OAuthTokens[0].ID,
Branch: "main",
},
Project: &Project{
ID: orgTest.DefaultProject.ID,
Expand All @@ -154,9 +155,15 @@ func TestStackReadUpdateDelete(t *testing.T) {

require.NoError(t, err)
require.NotNil(t, stack)
require.NotEmpty(t, stack.VCSRepo.Identifier)
require.NotEmpty(t, stack.VCSRepo.OAuthTokenID)
require.NotEmpty(t, stack.VCSRepo.Branch)

stackRead, err := client.Stacks.Read(ctx, stack.ID, nil)
require.NoError(t, err)
require.Equal(t, stack.VCSRepo.Identifier, stackRead.VCSRepo.Identifier)
require.Equal(t, stack.VCSRepo.OAuthTokenID, stackRead.VCSRepo.OAuthTokenID)
require.Equal(t, stack.VCSRepo.Branch, stackRead.VCSRepo.Branch)

assert.Equal(t, stack, stackRead)

Expand Down
30 changes: 29 additions & 1 deletion workspace_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,36 @@ func TestWorkspacesCreateTableDriven(t *testing.T) {
orgTest, orgTestCleanup := createOrganization(t, client)
t.Cleanup(orgTestCleanup)

oc, oaCleanup := createOAuthToken(t, client, orgTest)
t.Cleanup(oaCleanup)

workspaceTableTests := []WorkspaceTableTest{
{
scenario: "when options include vcs-repo",
options: &WorkspaceTableOptions{
createOptions: &WorkspaceCreateOptions{
Name: String("foobar"),
VCSRepo: &VCSRepoOptions{
Identifier: String("hashicorp/terraform-random-module"),
OAuthTokenID: &oc.ID,
Branch: String("main"),
},
},
},
assertion: func(t *testing.T, w *Workspace, options *WorkspaceTableOptions, err error) {
require.NoError(t, err)
require.NotNil(t, w)
require.NotEmpty(t, w.VCSRepo.Identifier)
require.NotEmpty(t, w.VCSRepo.OAuthTokenID)
require.NotEmpty(t, w.VCSRepo.Branch)

wRead, err := client.Workspaces.ReadByID(ctx, w.ID)
require.NoError(t, err)
require.Equal(t, w.VCSRepo.Identifier, wRead.VCSRepo.Identifier)
require.Equal(t, w.VCSRepo.OAuthTokenID, wRead.VCSRepo.OAuthTokenID)
require.Equal(t, w.VCSRepo.Branch, wRead.VCSRepo.Branch)
},
},
{
scenario: "when options include tags-regex",
options: &WorkspaceTableOptions{
Expand Down Expand Up @@ -450,7 +479,6 @@ func TestWorkspacesCreateTableDrivenWithGithubApp(t *testing.T) {
ctx := context.Background()

orgTest1, orgTestCleanup := createOrganization(t, client)

t.Cleanup(orgTestCleanup)

workspaceTableTests := []WorkspaceTableTest{
Expand Down

0 comments on commit d0cc62d

Please sign in to comment.