forked from taiidani/terraform-provider-jenkins
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding acceptance tests through Codeship (#2)
* Initial work on acceptance tests * Adding Terraform CCI2 dependency * CircleCI's Docker support still lacking. Trying Codeship * Formatting * Still going to need networking * Further Codeship work * Hmm, trying more stuff * These mistakes are all me * More * And more * Optimizing * Cleaning up
- Loading branch information
Ryan Nixon
committed
Dec 25, 2018
1 parent
83f00e9
commit 062b4a0
Showing
15 changed files
with
259 additions
and
43 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
.DS_Store | ||
example.tf | ||
terraform.tfplan | ||
terraform.tfstate | ||
terraform.tfstate* | ||
./*.tfstate | ||
.terraform/ | ||
*.test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
version: '2' | ||
|
||
services: | ||
runner: | ||
build: | ||
image: codeship | ||
dockerfile: codeship.dockerfile | ||
depends_on: [ jenkins-provider-acc ] | ||
cached: true | ||
|
||
jenkins-provider-acc: | ||
build: | ||
image: jenkins-provider-acc | ||
dockerfile: jenkins/test-fixtures/Dockerfile | ||
cached: true | ||
environment: | ||
JAVA_OPTS: "-Djenkins.install.runSetupWizard=false" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
- name: Run Acceptance Tests | ||
service: runner | ||
command: make testacc ACC_USE_DOCKER=false ACC_DOCKER_URL=jenkins-provider-acc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
FROM circleci/golang:1.11 | ||
|
||
WORKDIR /app | ||
COPY go.mod go.sum /app/ | ||
RUN go mod download | ||
|
||
COPY . /app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package jenkins | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform/helper/schema" | ||
"github.com/hashicorp/terraform/terraform" | ||
) | ||
|
||
var testAccProvider *schema.Provider | ||
var testAccProviders map[string]terraform.ResourceProvider | ||
|
||
func init() { | ||
testAccProvider = Provider().(*schema.Provider) | ||
testAccProviders = map[string]terraform.ResourceProvider{ | ||
"jenkins": testAccProvider, | ||
} | ||
} | ||
|
||
func TestProvider(t *testing.T) { | ||
if err := testAccProvider.InternalValidate(); err != nil { | ||
t.Fatalf("err: %s", err) | ||
} | ||
} | ||
|
||
func testAccPreCheck(t *testing.T) { | ||
if v := os.Getenv("JENKINS_URL"); v == "" { | ||
t.Fatal("JENKINS_URL must be set for acceptance tests") | ||
} | ||
if v := os.Getenv("JENKINS_USERNAME"); v == "" { | ||
t.Fatal("JENKINS_USERNAME must be set for acceptance tests") | ||
} | ||
if v := os.Getenv("JENKINS_PASSWORD"); v == "" { | ||
t.Fatal("JENKINS_PASSWORD must be set for acceptance tests") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package jenkins | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
jenkins "github.com/bndr/gojenkins" | ||
"github.com/hashicorp/terraform/helper/acctest" | ||
"github.com/hashicorp/terraform/helper/resource" | ||
"github.com/hashicorp/terraform/terraform" | ||
) | ||
|
||
func TestAccJenkinsFolder_basic(t *testing.T) { | ||
randString := acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum) | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckJenkinsFolderDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccJenkinsFolderConfig(randString), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccCheckJenkinsFolderDestroy(s *terraform.State) error { | ||
client := testAccProvider.Meta().(*jenkins.Jenkins) | ||
|
||
for _, rs := range s.RootModule().Resources { | ||
if rs.Type != "jenkins_folder" { | ||
continue | ||
} | ||
|
||
_, err := client.GetJob(rs.Primary.ID) | ||
if err == nil { | ||
return fmt.Errorf("Folder %s still exists", rs.Primary.ID) | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func testAccJenkinsFolderConfig(randString string) string { | ||
return fmt.Sprintf(` | ||
resource "jenkins_folder" "foo" { | ||
name = "tf-acc-test-%s" | ||
description = "Terraform acceptance tests %s" | ||
} | ||
`, randString, randString) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package jenkins | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
jenkins "github.com/bndr/gojenkins" | ||
"github.com/hashicorp/terraform/helper/acctest" | ||
"github.com/hashicorp/terraform/helper/resource" | ||
"github.com/hashicorp/terraform/terraform" | ||
) | ||
|
||
func TestAccJenkinsJob_basic(t *testing.T) { | ||
randString := acctest.RandStringFromCharSet(10, acctest.CharSetAlphaNum) | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckJenkinsJobDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccJenkinsJobConfig(randString), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccCheckJenkinsJobDestroy(s *terraform.State) error { | ||
client := testAccProvider.Meta().(*jenkins.Jenkins) | ||
|
||
for _, rs := range s.RootModule().Resources { | ||
if rs.Type != "jenkins_job" { | ||
continue | ||
} | ||
|
||
_, err := client.GetJob(rs.Primary.ID) | ||
if err == nil { | ||
return fmt.Errorf("Job %s still exists", rs.Primary.ID) | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func testAccJenkinsJobConfig(randString string) string { | ||
return fmt.Sprintf(` | ||
resource "jenkins_job" "foo" { | ||
name = "tf-acc-test-%s" | ||
template = "${file("resource_jenkins_job_test.xml")}" | ||
parameters = { | ||
description = "Acceptance testing Jenkins provider" | ||
} | ||
} | ||
`, randString) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<flow-definition plugin="workflow-job@2.25"> | ||
<actions/> | ||
<description>{{ .Parameters.description }}</description> | ||
<keepDependencies>false</keepDependencies> | ||
<properties/> | ||
<definition class="org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition" plugin="workflow-cps@2.59"> | ||
<scm class="hudson.plugins.git.GitSCM" plugin="git@3.9.1"> | ||
<configVersion>2</configVersion> | ||
<userRemoteConfigs> | ||
<hudson.plugins.git.UserRemoteConfig> | ||
<url>https://github.com/taiidani/terraform-provider-jenkins.git</url> | ||
<credentialsId>github</credentialsId> | ||
</hudson.plugins.git.UserRemoteConfig> | ||
</userRemoteConfigs> | ||
<branches> | ||
<hudson.plugins.git.BranchSpec> | ||
<name>*/master</name> | ||
</hudson.plugins.git.BranchSpec> | ||
</branches> | ||
<doGenerateSubmoduleConfigurations>false</doGenerateSubmoduleConfigurations> | ||
<submoduleCfg class="list"/> | ||
<extensions/> | ||
</scm> | ||
<scriptPath>Jenkinsfile</scriptPath> | ||
<lightweight>true</lightweight> | ||
</definition> | ||
<triggers/> | ||
<disabled>false</disabled> | ||
</flow-definition> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.