Skip to content

Commit

Permalink
Decoupling acceptance tests from the real AWS account
Browse files Browse the repository at this point in the history
  • Loading branch information
QubitPi committed Jul 10, 2024
1 parent a13b784 commit e755fc1
Show file tree
Hide file tree
Showing 8 changed files with 6 additions and 336 deletions.
54 changes: 5 additions & 49 deletions .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,38 +59,9 @@ jobs:
make build
make test
docker-image:
name: Publish test docker images for acceptance tests
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: jack20191124
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Push image to DockerHub
uses: docker/build-push-action@v3
with:
context: .github/docker/
push: true
tags: jack20191124/packer-plugin-hashicorp-aws-acc-test-base:latest
- name: Push image Description
uses: peter-evans/dockerhub-description@v4
with:
username: jack20191124
password: ${{ secrets.DOCKERHUB_TOKEN }}
repository: jack20191124/packer-plugin-hashicorp-aws-acc-test-base
readme-filepath: .github/docker/README.md

acceptance-tests:
name: Packer Plugin Acceptance Tests
needs: [tests, docker-image]
needs: tests
outputs:
outcome: ${{ job.status }}
continue-on-error: true
Expand All @@ -103,31 +74,16 @@ jobs:
- name: Install Packer
uses: hashicorp/setup-packer@main
- name: Build plugin
run: go build -ldflags="-X github.com/QubitPi/packer-plugin-hashicorp-aws/version.VersionPrerelease=dev" -o packer-plugin-hashicorp-aws
run: go build -ldflags="-X github.com/paion-data/packer-plugin-paion-data/version.VersionPrerelease=dev" -o packer-plugin-paion-data
- name: Install dependencies
run: |
packer plugins install github.com/hashicorp/amazon
packer plugins install github.com/hashicorp/docker
run: packer plugins install github.com/hashicorp/docker
- name: Install plugin
run: packer plugins install --path packer-plugin-hashicorp-aws github.com/QubitPi/hashicorp-aws
run: packer plugins install --path packer-plugin-paion-data github.com/paion-data/paion-data
- name: Run all acceptance tests
run: PACKER_ACC=1 go test -count 1 -v ./... -timeout=120m
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}

release:
needs: [acceptance-tests]
if: ${{ github.ref == 'refs/heads/master' && github.repository != 'QubitPi/hashicorp-packer-plugin-scaffolding' }}
if: ${{ github.ref == 'refs/heads/master' }}
uses: ./.github/workflows/release.yml
secrets: inherit

slack-notification:
name: Send Slack Notification
if: github.ref != 'refs/heads/master'
needs: acceptance-tests
uses: QubitPi/hashicorp-aws/.github/workflows/slack-notification.yml@master
with:
job-status: ${{ needs.acceptance-tests.outputs.outcome }}
secrets:
slack-webhook-url: ${{ secrets.SLACK_WEBHOOK_URL }}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
main
packer-plugin-hashicorp-aws
packer-plugin-paion-data
**/packer_log*.txt
**/git_*test.pkr.hcl
crash.log
Expand Down
47 changes: 0 additions & 47 deletions provisioner/react/provisioner_acc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ import (
"github.com/hashicorp/packer-plugin-sdk/acctest"
)

//go:embed test-fixtures/template-aws.pkr.hcl
var testProvisionerHCL2AWS string

//go:embed test-fixtures/template-docker.pkr.hcl
var testProvisionerHCL2Docker string

Expand All @@ -28,50 +25,6 @@ func TestAccReactProvisioner(t *testing.T) {
return
}

testCaseAws := &acctest.PluginTestCase{
Name: "react_provisioner_aws_test",
Setup: func() error {
return nil
},
Teardown: func() error {
return nil
},
Template: strings.Replace(testProvisionerHCL2AWS, "/my/path/to/dist", tempFile.Name(), -1),
Type: "hashicorp-aws-react-provisioner",
Check: func(buildCommand *exec.Cmd, logfile string) error {
if buildCommand.ProcessState != nil {
if buildCommand.ProcessState.ExitCode() != 0 {
return fmt.Errorf("Bad exit code. Logfile: %s", logfile)
}
}

logs, err := os.Open(logfile)
if err != nil {
return fmt.Errorf("Unable find %s", logfile)
}
defer logs.Close()

logsBytes, err := ioutil.ReadAll(logs)
if err != nil {
return fmt.Errorf("Unable to read %s", logfile)
}
logsString := string(logsBytes)

errorString := "\\[ERROR\\] Remote command exited with"
if matched, _ := regexp.MatchString(".*"+errorString+".*", logsString); matched {
t.Fatalf("Acceptance tests for %s failed. Please search for '%s' in log file at %s", "webservice provisioner", errorString, logfile)
}

provisionerOutputLog := "amazon-ebs.hashicorp-aws: AMIs were created:"
if matched, _ := regexp.MatchString(provisionerOutputLog+".*", logsString); !matched {
t.Fatalf("logs doesn't contain expected output %q", logsString)
}

return nil
},
}
acctest.TestPlugin(t, testCaseAws)

testCaseDocker := &acctest.PluginTestCase{
Name: "react_provisioner_docker_test",
Setup: func() error {
Expand Down
50 changes: 0 additions & 50 deletions provisioner/react/test-fixtures/template-aws.pkr.hcl

This file was deleted.

46 changes: 0 additions & 46 deletions provisioner/sonatype-nexus-repository/provisioner_acc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,56 +15,10 @@ import (
"github.com/hashicorp/packer-plugin-sdk/acctest"
)

//go:embed test-fixtures/template-aws.pkr.hcl
var testProvisionerHCL2AWS string

//go:embed test-fixtures/template-docker.pkr.hcl
var testProvisionerHCL2Docker string

func TestAccSonatypeNexusRepositoryProvisioner(t *testing.T) {
testCaseAws := &acctest.PluginTestCase{
Name: "sonatype_nexus_repository_provisioner_aws_test",
Setup: func() error {
return nil
},
Teardown: func() error {
return nil
},
Template: testProvisionerHCL2AWS,
Type: "hashicorp-aws-sonatype-nexus-repository-provisioner",
Check: func(buildCommand *exec.Cmd, logfile string) error {
if buildCommand.ProcessState != nil {
if buildCommand.ProcessState.ExitCode() != 0 {
return fmt.Errorf("Bad exit code. Logfile: %s", logfile)
}
}

logs, err := os.Open(logfile)
if err != nil {
return fmt.Errorf("Unable find %s", logfile)
}
defer logs.Close()

logsBytes, err := ioutil.ReadAll(logs)
if err != nil {
return fmt.Errorf("Unable to read %s", logfile)
}
logsString := string(logsBytes)

errorString := "\\[ERROR\\] Remote command exited with"
if matched, _ := regexp.MatchString(".*"+errorString+".*", logsString); matched {
t.Fatalf("%s\n Acceptance tests for %s failed. Please search for '%s' in log file at %s", logsString, "sonatype-nexus-repository provisioner", errorString, logfile)
}

provisionerOutputLog := "amazon-ebs.hashicorp-aws: AMIs were created:"
if matched, _ := regexp.MatchString(provisionerOutputLog+".*", logsString); !matched {
t.Fatalf("%s\n logs doesn't contain expected output %q", logsString, provisionerOutputLog)
}
return nil
},
}
acctest.TestPlugin(t, testCaseAws)

testCaseDocker := &acctest.PluginTestCase{
Name: "sonatype_nexus_repository_provisioner_docker_test",
Setup: func() error {
Expand Down

This file was deleted.

47 changes: 0 additions & 47 deletions provisioner/webservice/provisioner_acc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ import (
"github.com/hashicorp/packer-plugin-sdk/acctest"
)

//go:embed test-fixtures/template-aws.pkr.hcl
var testProvisionerHCL2AWS string

//go:embed test-fixtures/template-docker.pkr.hcl
var testProvisionerHCL2Docker string

Expand All @@ -28,50 +25,6 @@ func TestAccWebserviceProvisioner(t *testing.T) {
return
}

testCaseAws := &acctest.PluginTestCase{
Name: "webservice_provisioner_aws_test",
Setup: func() error {
return nil
},
Teardown: func() error {
return nil
},
Template: strings.Replace(testProvisionerHCL2AWS, "my-webservice.war", tempFile.Name(), -1),
Type: "hashicorp-aws-webservice-provisioner",
Check: func(buildCommand *exec.Cmd, logfile string) error {
if buildCommand.ProcessState != nil {
if buildCommand.ProcessState.ExitCode() != 0 {
return fmt.Errorf("Bad exit code. Logfile: %s", logfile)
}
}

logs, err := os.Open(logfile)
if err != nil {
return fmt.Errorf("Unable find %s", logfile)
}
defer logs.Close()

logsBytes, err := ioutil.ReadAll(logs)
if err != nil {
return fmt.Errorf("Unable to read %s", logfile)
}
logsString := string(logsBytes)

errorString := "\\[ERROR\\] Remote command exited with"
if matched, _ := regexp.MatchString(".*"+errorString+".*", logsString); matched {
t.Fatalf("Acceptance tests for %s failed. Please search for '%s' in log file at %s", "webservice provisioner", errorString, logfile)
}

provisionerOutputLog := "amazon-ebs.hashicorp-aws: AMIs were created:"
if matched, _ := regexp.MatchString(provisionerOutputLog+".*", logsString); !matched {
t.Fatalf("logs doesn't contain expected output %q", logsString)
}

return nil
},
}
acctest.TestPlugin(t, testCaseAws)

testCaseDocker := &acctest.PluginTestCase{
Name: "webservice_provisioner_docker_test",
Setup: func() error {
Expand Down
Loading

0 comments on commit e755fc1

Please sign in to comment.