-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Add acceptance test for fabric_ports and GHA for fabric tests (#…
…520) * Acceptance Tests Added for: * `data "equinix_fabric_port"` * `data "equinix_fabric_ports"` * GHA added for Fabric Acceptance Tests * Uses Two sets of Secrets for Different Tests * Fabric Tests must be tagged PNFV or PFCR to be picked up by GHA * Added placeholder for potential addition of sweepers
- Loading branch information
Showing
3 changed files
with
260 additions
and
1 deletion.
There are no files selected for viewing
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,195 @@ | ||
name: Fabric Acceptance Tests | ||
# This workflow determines whether a PR comes from an external fork | ||
# (which requires approval from us) or from a branch on this repository | ||
# (which means it was made by us and can run immediately). Once a PR | ||
# is approved, the PR code gains access to secrets referenced in this | ||
# workflow. | ||
|
||
# The 'build' job and subsequent jobs, are executed only when the pull | ||
# request is not a draft, regardless of whether it is from an internal | ||
# branch or external fork. | ||
|
||
# Any changes to this job, even from internal contributors, require heavy scrutiny. | ||
|
||
on: | ||
pull_request_target: | ||
types: [opened, synchronize, reopened, ready_for_review] | ||
paths: | ||
- '**fabric**' | ||
- '!LICENSE' | ||
- '!**.md' | ||
- '!website/**' | ||
- '!docs/**' | ||
- '!.github/ISSUE_TEMPLATE/**' | ||
workflow_dispatch: | ||
|
||
permissions: | ||
pull-requests: read | ||
contents: read | ||
|
||
jobs: | ||
|
||
authorize: | ||
if: (github.event_name == 'workflow_dispatch') || (github.event_name == 'pull_request_target' && github.event.pull_request.draft == false) | ||
environment: | ||
${{ github.event_name == 'pull_request_target' && | ||
github.event.pull_request.head.repo.full_name != github.repository && | ||
'external' || 'internal' }} | ||
runs-on: ubuntu-latest | ||
concurrency: | ||
group: ${{ github.event_name == 'pull_request_target' && format('acctest-authorize-pr-{0}', github.event.pull_request.number) || 'acctest-authorize' }} | ||
cancel-in-progress: true | ||
steps: | ||
- run: true | ||
|
||
build: | ||
name: Build | ||
needs: authorize | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 10 | ||
steps: | ||
|
||
- name: Check out code into the Go module directory | ||
uses: actions/checkout@v4 | ||
with: | ||
ref: ${{ github.event.pull_request.head.sha || github.ref }} | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version-file: './go.mod' | ||
id: go | ||
|
||
- name: Get dependencies | ||
run: | | ||
go mod download | ||
- name: Build | ||
run: | | ||
go build -v . | ||
test-PFNV: | ||
name: Matrix Test | ||
needs: build | ||
concurrency: fabricacctestpfnv | ||
runs-on: ubuntu-latest | ||
env: | ||
EQUINIX_API_ENDPOINT: "https://uatapi.equinix.com" | ||
timeout-minutes: 240 | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
version: | ||
- stable | ||
terraform: | ||
- '1.5' | ||
steps: | ||
|
||
- name: Check out code into the Go module directory | ||
uses: actions/checkout@v4 | ||
with: | ||
ref: ${{ github.event.pull_request.head.sha || github.ref }} | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version-file: './go.mod' | ||
id: go | ||
|
||
- name: Get dependencies | ||
run: | | ||
go mod download | ||
- name: TF Fabric PNFV acceptance tests | ||
timeout-minutes: 180 | ||
env: | ||
TF_ACC: "1" | ||
TF_ACC_TERRAFORM_VERSION: ${{ matrix.terraform }} | ||
EQUINIX_API_CLIENTID: ${{ secrets.EQUINIX_API_CLIENTID_PNFV }} | ||
EQUINIX_API_CLIENTSECRET: ${{ secrets.EQUINIX_API_CLIENTSECRET_PNFV }} | ||
METAL_AUTH_TOKEN: ${{ secrets.METAL_AUTH_TOKEN }} | ||
run: | | ||
go test ./... -v -coverprofile coverage_pnfv.txt -covermode=atomic -count 1 -parallel 8 -run "(PNFV)" -timeout 180m | ||
- name: Sweeper PNFV | ||
if: ${{ always() }} | ||
env: | ||
EQUINIX_API_CLIENTID: ${{ secrets.EQUINIX_API_CLIENTID_PNFV }} | ||
EQUINIX_API_CLIENTSECRET: ${{ secrets.EQUINIX_API_CLIENTSECRET_PNFV }} | ||
METAL_AUTH_TOKEN: ${{ secrets.METAL_AUTH_TOKEN }} | ||
SWEEP: "all" #Flag required to define the regions that the sweeper is to be ran in | ||
SWEEP_ALLOW_FAILURES: "true" #Enable to allow Sweeper Tests to continue after failures | ||
SWEEP_DIR: "./equinix" | ||
run: | | ||
# Added sweep-run to filter Fabric PNFV test | ||
go test ${SWEEP_DIR} -v -timeout 180m -sweep=${SWEEP} -sweep-allow-failures=${SWEEP_ALLOW_FAILURES} -sweep-run=$(grep -o 'AddTestSweepers("[^"]*PNFV"' equinix/resource_fabric_* | cut -d '"' -f2 | paste -s -d, -) | ||
- name: Upload coverage to Codecov | ||
if: ${{ always() }} | ||
uses: codecov/codecov-action@v3 | ||
with: | ||
token: ${{ secrets.CODECOV_TOKEN }} | ||
files: ./coverage_pnfv.txt | ||
|
||
test-PFCR: | ||
name: Matrix Test | ||
needs: build | ||
concurrency: fabricacctestpfcr | ||
runs-on: ubuntu-latest | ||
env: | ||
EQUINIX_API_ENDPOINT: "https://uatapi.equinix.com" | ||
timeout-minutes: 240 | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
version: | ||
- stable | ||
terraform: | ||
- '1.5' | ||
steps: | ||
|
||
- name: Check out code into the Go module directory | ||
uses: actions/checkout@v4 | ||
with: | ||
ref: ${{ github.event.pull_request.head.sha || github.ref }} | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version-file: './go.mod' | ||
id: go | ||
|
||
- name: Get dependencies | ||
run: | | ||
go mod download | ||
- name: TF Fabric PFCR acceptance tests | ||
timeout-minutes: 180 | ||
env: | ||
TF_ACC: "1" | ||
TF_ACC_TERRAFORM_VERSION: ${{ matrix.terraform }} | ||
EQUINIX_API_CLIENTID: ${{ secrets.EQUINIX_API_CLIENTID_PFCR }} | ||
EQUINIX_API_CLIENTSECRET: ${{ secrets.EQUINIX_API_CLIENTSECRET_PFCR }} | ||
METAL_AUTH_TOKEN: ${{ secrets.METAL_AUTH_TOKEN }} | ||
run: | | ||
go test ./... -v -coverprofile coverage_pfcr.txt -covermode=atomic -count 1 -parallel 8 -run "(PFCR)" -timeout 180m | ||
- name: Sweeper PFCR | ||
if: ${{ always() }} | ||
env: | ||
EQUINIX_API_CLIENTID: ${{ secrets.EQUINIX_API_CLIENTID_PFCR }} | ||
EQUINIX_API_CLIENTSECRET: ${{ secrets.EQUINIX_API_CLIENTSECRET_PFCR }} | ||
METAL_AUTH_TOKEN: ${{ secrets.METAL_AUTH_TOKEN }} | ||
SWEEP: "all" #Flag required to define the regions that the sweeper is to be ran in | ||
SWEEP_ALLOW_FAILURES: "true" #Enable to allow Sweeper Tests to continue after failures | ||
SWEEP_DIR: "./equinix" | ||
run: | | ||
# Added sweep-run to filter Fabric PFCR test | ||
go test ${SWEEP_DIR} -v -timeout 180m -sweep=${SWEEP} -sweep-allow-failures=${SWEEP_ALLOW_FAILURES} -sweep-run=$(grep -o 'AddTestSweepers("[^"]*PFCR"' equinix/resource_fabric_* | cut -d '"' -f2 | paste -s -d, -) | ||
- name: Upload coverage to Codecov | ||
if: ${{ always() }} | ||
uses: codecov/codecov-action@v3 | ||
with: | ||
token: ${{ secrets.CODECOV_TOKEN }} | ||
files: ./coverage_pfcr.txt |
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,64 @@ | ||
package equinix | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
) | ||
|
||
func TestAccDataSourceFabricPort_PNFV(t *testing.T) { | ||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
ExternalProviders: testExternalProviders, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testDataSourceFabricPort("c4d85dbe-fa99-a999-f7e0-306a5c00af26"), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr( | ||
"data.equinix_fabric_port.test", "name", "eqx-nfv-201091-CX-SV1-L-Dot1q-BO-20G-PRI-JP-395"), | ||
resource.TestCheckResourceAttr( | ||
"data.equinix_fabric_port.test", "type", "XF_PORT"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testDataSourceFabricPort(port_uuid string) string { | ||
return fmt.Sprintf(` | ||
data "equinix_fabric_port" "test" { | ||
uuid = "%s" | ||
}`, | ||
port_uuid) | ||
} | ||
|
||
func TestAccDataSourceFabricPorts_PNFV(t *testing.T) { | ||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
ExternalProviders: testExternalProviders, | ||
Providers: testAccProviders, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testDataSourceFabricPorts("eqx-nfv-201091-CX-SV1-L-Dot1q-BO-20G-PRI-JP-395"), | ||
Check: resource.ComposeTestCheckFunc( | ||
resource.TestCheckResourceAttr( | ||
"data.equinix_fabric_ports.test", "id", "c4d85dbe-fa99-a999-f7e0-306a5c00af26"), | ||
resource.TestCheckResourceAttr( | ||
"data.equinix_fabric_ports.test", "data.0.type", "XF_PORT"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testDataSourceFabricPorts(port_name string) string { | ||
return fmt.Sprintf(` | ||
data "equinix_fabric_ports" "test" { | ||
filters { | ||
name = "%s" | ||
} | ||
}`, | ||
port_name) | ||
} |
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