Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Project Import #28

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
9 changes: 6 additions & 3 deletions jira/resource_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ func resourceProject() *schema.Resource {
Read: resourceProjectRead,
Update: resourceProjectUpdate,
Delete: resourceProjectDelete,
Importer: &schema.ResourceImporter{
State: schema.ImportStatePassthrough,
},

Schema: map[string]*schema.Schema{
"project_id": &schema.Schema{
Expand Down Expand Up @@ -137,7 +140,7 @@ func resourceProject() *schema.Resource {

// resourceProjectCreate creates a new jira issue using the jira api
func resourceProjectCreate(d *schema.ResourceData, m interface{}) error {
config := m.(*Config)
client := m.(*Config).jiraClient

sharedProjectID, useSharedConfiguration := d.GetOk("shared_configuration_project_id")
if useSharedConfiguration {
Expand All @@ -152,7 +155,7 @@ func resourceProjectCreate(d *schema.ResourceData, m interface{}) error {

endpoint := projectWithSharedConfigurationAPIEndpoint(sharedProjectID.(int))

err := request(config.jiraClient, "POST", endpoint, project, returnedProject)
err := request(client, "POST", endpoint, project, returnedProject)

if err != nil {
return errors.Wrap(err, "Request failed")
Expand Down Expand Up @@ -186,7 +189,7 @@ func resourceProjectCreate(d *schema.ResourceData, m interface{}) error {

returnedProject := new(IDResponse)

err := request(config.jiraClient, "POST", projectAPIEndpoint, project, returnedProject)
err := request(client, "POST", projectAPIEndpoint, project, returnedProject)
if err != nil {
return errors.Wrap(err, "Request failed")
}
Expand Down
20 changes: 18 additions & 2 deletions jira/resource_project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
func TestAccJiraProject_basic(t *testing.T) {
rInt := acctest.RandInt()

resourceName := "jira_project.foo"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Expand All @@ -20,16 +22,24 @@ func TestAccJiraProject_basic(t *testing.T) {
{
Config: testAccJiraProjectConfig(rInt),
Check: resource.ComposeTestCheckFunc(
testAccCheckJiraProjectExists("jira_project.foo"),
testAccCheckJiraProjectExists(resourceName),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"shared_configuration_project_id"},
},
},
})
}

func TestAccJiraProject_shared(t *testing.T) {
rInt := acctest.RandInt()

resourceName := "jira_project.foo_shared"

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Expand All @@ -38,9 +48,15 @@ func TestAccJiraProject_shared(t *testing.T) {
{
Config: testAccJiraSharedProjectConfig(rInt),
Check: resource.ComposeTestCheckFunc(
testAccCheckJiraProjectExists("jira_project.foo_shared"),
testAccCheckJiraProjectExists(resourceName),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"shared_configuration_project_id"},
},
},
})
}
Expand Down