Skip to content

Commit

Permalink
generated mocks and added project option to workspaces
Browse files Browse the repository at this point in the history
  • Loading branch information
hs26gill committed Nov 8, 2022
1 parent 6ae4ea3 commit 64d7011
Show file tree
Hide file tree
Showing 8 changed files with 214 additions and 4 deletions.
1 change: 1 addition & 0 deletions generate_mocks.sh
Expand Up @@ -61,3 +61,4 @@ mockgen -source=variable_set_variable.go -destination=mocks/variable_set_variabl
mockgen -source=workspace.go -destination=mocks/workspace_mocks.go -package=mocks
mockgen -source=workspace_run_task.go -destination=mocks/workspace_run_tasks_mocks.go -package=mocks
mockgen -source=agent.go -destination=mocks/agents.go -package=mocks
mockgen -source=project.go -destination=mocks/project_mocks.go -package=mocks
15 changes: 15 additions & 0 deletions mocks/organization_mocks.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

110 changes: 110 additions & 0 deletions mocks/project_mocks.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion projects.go → project.go
Expand Up @@ -63,7 +63,7 @@ type ProjectCreateOptions struct {
// https://jsonapi.org/format/#crud-creating
Type string `jsonapi:"primary,projects"`

// Required: A name to identify the agent pool.
// Required: A name to identify the project.
Name *string `jsonapi:"attr,name"`
}

Expand Down
3 changes: 1 addition & 2 deletions projects_integration_test.go
Expand Up @@ -191,8 +191,7 @@ func TestProjectsDelete(t *testing.T) {
orgTest, orgTestCleanup := createOrganization(t, client)
defer orgTestCleanup()

pTest, pTestCleanup := createProject(t, client, orgTest)
defer pTestCleanup()
pTest, _ := createProject(t, client, orgTest)

t.Run("with valid options", func(t *testing.T) {
err := client.Projects.Delete(ctx, pTest.ID)
Expand Down
2 changes: 1 addition & 1 deletion tfe.go
Expand Up @@ -381,6 +381,7 @@ func NewClient(cfg *Config) (*Client, error) {
client.PolicySetParameters = &policySetParameters{client: client}
client.PolicySets = &policySets{client: client}
client.PolicySetVersions = &policySetVersions{client: client}
client.Projects = &projects{client: client}
client.RegistryModules = &registryModules{client: client}
client.RegistryProviderPlatforms = &registryProviderPlatforms{client: client}
client.RegistryProviders = &registryProviders{client: client}
Expand All @@ -404,7 +405,6 @@ func NewClient(cfg *Config) (*Client, error) {
client.VariableSetVariables = &variableSetVariables{client: client}
client.WorkspaceRunTasks = &workspaceRunTasks{client: client}
client.Workspaces = &workspaces{client: client}
client.Projects = &projects{client: client}

client.Meta = Meta{
IPRanges: &ipRanges{client: client},
Expand Down
8 changes: 8 additions & 0 deletions workspace.go
Expand Up @@ -363,6 +363,10 @@ type WorkspaceCreateOptions struct {
// A list of tags to attach to the workspace. If the tag does not already
// exist, it is created and added to the workspace.
Tags []*Tag `jsonapi:"relation,tags,omitempty"`

// Associated Project with the workspace. If not provided, default project
// of the organization will be assigned to the workspace
Project *Project `jsonapi:"relation,project,omitempty"`
}

// TODO: move this struct out. VCSRepoOptions is used by workspaces, policy sets, and registry modules
Expand Down Expand Up @@ -466,6 +470,10 @@ type WorkspaceUpdateOptions struct {
// the environment when multiple environments exist within the same
// repository.
WorkingDirectory *string `jsonapi:"attr,working-directory,omitempty"`

// Associated Project with the workspace. If not provided, default project
// of the organization will be assigned to the workspace
Project *Project `jsonapi:"relation,project,omitempty"`
}

// WorkspaceLockOptions represents the options for locking a workspace.
Expand Down
77 changes: 77 additions & 0 deletions workspace_integration_test.go
Expand Up @@ -327,6 +327,53 @@ func TestWorkspacesCreate(t *testing.T) {
orgTest, orgTestCleanup := createOrganization(t, client)
t.Cleanup(orgTestCleanup)

t.Run("with valid project option", func(t *testing.T) {
skipIfBeta(t)

options := WorkspaceCreateOptions{
Name: String(fmt.Sprintf("foo-%s", randomString(t))),
AllowDestroyPlan: Bool(false),
AutoApply: Bool(true),
Description: String("qux"),
AssessmentsEnabled: Bool(false),
FileTriggersEnabled: Bool(true),
Operations: Bool(true),
QueueAllRuns: Bool(true),
SpeculativeEnabled: Bool(true),
SourceName: String("my-app"),
SourceURL: String("http://my-app-hostname.io"),
StructuredRunOutputEnabled: Bool(true),
TerraformVersion: String("0.11.0"),
TriggerPrefixes: []string{"/modules", "/shared"},
WorkingDirectory: String("bar/"),
Project: orgTest.DefaultProject,
Tags: []*Tag{
{
Name: "tag1",
},
{
Name: "tag2",
},
},
}

w, err := client.Workspaces.Create(ctx, orgTest.Name, options)
require.NoError(t, err)

// Get a refreshed view from the API.
refreshed, err := client.Workspaces.Read(ctx, orgTest.Name, *options.Name)
require.NoError(t, err)

for _, item := range []*Workspace{
w,
refreshed,
} {
assert.NotEmpty(t, item.ID)
assert.Equal(t, *options.Name, item.Name)
assert.Equal(t, options.Project.ID, item.Project.ID)
}
})

t.Run("with valid options", func(t *testing.T) {
options := WorkspaceCreateOptions{
Name: String("foo"),
Expand Down Expand Up @@ -763,6 +810,36 @@ func TestWorkspacesUpdate(t *testing.T) {
assert.Equal(t, wTest.WorkingDirectory, wAfter.WorkingDirectory)
})

t.Run("when updating project", func(t *testing.T) {
skipIfBeta(t)

kBefore, kTestCleanup := createProject(t, client, orgTest)
defer kTestCleanup()

wBefore, wBeforeCleanup := createWorkspaceWithOptions(t, client, orgTest, WorkspaceCreateOptions{
Name: String(randomString(t)),
Project: kBefore,
})
defer wBeforeCleanup()

options := WorkspaceUpdateOptions{
Name: String(wBefore.Name),
AllowDestroyPlan: Bool(false),
AutoApply: Bool(true),
Operations: Bool(true),
QueueAllRuns: Bool(true),
AssessmentsEnabled: Bool(true),
TerraformVersion: String("0.15.4"),
Project: orgTest.DefaultProject,
}

wAfter, err := client.Workspaces.Update(ctx, orgTest.Name, wBefore.Name, options)
require.NoError(t, err)

assert.Equal(t, wBefore.Name, wAfter.Name)
assert.Equal(t, wAfter.Project.ID, orgTest.DefaultProject.ID)
})

t.Run("with valid options", func(t *testing.T) {
options := WorkspaceUpdateOptions{
Name: String(randomString(t)),
Expand Down

0 comments on commit 64d7011

Please sign in to comment.