Skip to content

Commit

Permalink
jsonapi fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mwhooker committed Mar 19, 2021
1 parent 434fbdd commit 6843f47
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 13 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module github.com/hashicorp/go-tfe

require (
github.com/davecgh/go-spew v1.1.1
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/google/go-querystring v1.0.0
github.com/hashicorp/go-cleanhttp v0.5.0
github.com/hashicorp/go-retryablehttp v0.5.2
Expand Down
24 changes: 13 additions & 11 deletions workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ import (
// Compile-time proof of interface implementation.
var _ Workspaces = (*workspaces)(nil)

// workspaceReadme captures the workspace response with included README
type workspaceReadme struct {
Readme string `jsonapi:"attr,readme"`
}

// Workspaces describes all the workspace related methods that the Terraform
// Enterprise API supports.
//
Expand Down Expand Up @@ -83,6 +78,12 @@ type WorkspaceList struct {
Items []*Workspace
}

// WorkspaceReadme contains the readme of the workspace.
type WorkspaceReadme struct {
ID string `jsonapi:"primary,workspace-readme"`
Readme string `jsonapi:"attr,raw-markdown"`
}

// Workspace represents a Terraform Enterprise workspace.
type Workspace struct {
ID string `jsonapi:"primary,workspaces"`
Expand Down Expand Up @@ -116,10 +117,11 @@ type Workspace struct {
RunsCount int `jsonapi:"attr,workspace-kpis-runs-count"`

// Relations
AgentPool *AgentPool `jsonapi:"relation,agent-pool"`
CurrentRun *Run `jsonapi:"relation,current-run"`
Organization *Organization `jsonapi:"relation,organization"`
SSHKey *SSHKey `jsonapi:"relation,ssh-key"`
AgentPool *AgentPool `jsonapi:"relation,agent-pool"`
CurrentRun *Run `jsonapi:"relation,current-run"`
Organization *Organization `jsonapi:"relation,organization"`
SSHKey *SSHKey `jsonapi:"relation,ssh-key"`
Readme *WorkspaceReadme `jsonapi:"relation,readme"`
}

// VCSRepo contains the configuration of a VCS integration.
Expand Down Expand Up @@ -383,13 +385,13 @@ func (s *workspaces) Readme(ctx context.Context, workspaceID string) (io.Reader,
return nil, err
}

r := &workspaceReadme{}
r := &Workspace{}
err = s.client.do(ctx, req, r)
if err != nil {
return nil, err
}

return strings.NewReader(r.Readme), nil
return strings.NewReader(r.Readme.Readme), nil
}

// WorkspaceUpdateOptions represents the options for updating a workspace.
Expand Down
4 changes: 3 additions & 1 deletion workspace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,9 @@ func TestWorkspacesReadReadme(t *testing.T) {

readme, err := ioutil.ReadAll(w)
require.NoError(t, err)
require.Equal(t, "# README", readme)
require.Equal(t, `This is a simple test policy set for Terraform Cloud.
This is used as part of the CI setup for go-tfe, as documented in [tflocal_cloud](https://github.com/hashicorp/tflocal-cloud/).`, readme)
}

func TestWorkspacesReadByID(t *testing.T) {
Expand Down

0 comments on commit 6843f47

Please sign in to comment.