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

Acceptance test axel #184

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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
116 changes: 116 additions & 0 deletions .github/workflows/power-acceptance-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
name: PowerVS Acceptance Tests

on:
pull_request:
paths:
- 'ibm/service/power/*.go' # Trigger only when test files within power are changed
types: [opened, synchronize, reopened]

jobs:
acceptance-test:
runs-on: ubuntu-latest
if: github.repository == 'powervs-ibm/terraform-provider-ibm'

steps:
# Step 1: Checkout code
- name: Checkout code
uses: actions/checkout@v3

# Step 2: Set up Go environment
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: '1.22'
# Step 3: Cache Go modules
- name: Cache Go modules
uses: actions/cache@v3
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.mod', '**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-

# Step 4: Install dependencies
- name: Install dependencies
run: |
go mod tidy
go mod download

# Step 5: Install go-junit-report (before Step 7)
- name: Install go-junit-report
run: |
go install github.com/jstemmer/go-junit-report@latest

# Step 6 : Find modified files, set environment variables, and run tests
- name: Find modified files and run acceptance tests
run: |
# Create report file
mkdir -p test-results
# Get the list of modified Go files in the PR under the ibm/service/power directory
git fetch origin
modified_go_files=$(git diff --name-only origin/${{ github.event.pull_request.base.ref }} -- 'ibm/service/power/*.go')

echo "Modified files: $modified_go_files"

# Initialize an empty list for test files
modified_test_files=""

# Loop through modified Go files to identify corresponding test files
for file in $modified_go_files; do
# Skip constants.go since it has no corresponding test file
if [[ "$file" == "ibm/service/power/ibm_pi_constants.go" ]]; then
echo "Skipping ibm_pi_constants.go as it has no test file."
continue
fi

# Get the test file corresponding to the modified Go file by replacing .go with _test.go
test_file="${file%.go}_test.go"

# If the test file exists, add it to the list of test files to run
if [ -f "$test_file" ]; then
modified_test_files+=" $test_file"
fi
done

# If there are modified test files, run the tests
if [ -n "$modified_test_files" ]; then
echo "Modified test files: $modified_test_files"
go test -v -tags=all -test.v -test.run '^TestAcc' $modified_test_files 2>&1 | tee test-results/test-report.log
if grep -q 'FAIL' test-results/test-report.log; then
exit 1
fi

# go test -v -tags=all -test.v -test.run '^TestAcc' $modified_test_files 2>&1 | grep -E '^(=== RUN|--- PASS|--- FAIL|PASS|FAIL)' | tee test-results/test-report.log

else
echo "No modified test files detected."
fi
env:
TF_ACC: ${{ secrets.TF_ACC }}
TF_CLI_ARGS_plan: ${{ secrets.TF_CLI_ARGS_plan }}
TF_CLI_ARGS_apply: ${{ secrets.TF_CLI_ARGS_apply }}
IC_API_KEY: ${{ secrets.IC_API_KEY }}
IAAS_CLASSIC_API_KEY: ${{ secrets.IAAS_CLASSIC_API_KEY }}
IAAS_CLASSIC_USERNAME: ${{ secrets.IAAS_CLASSIC_USERNAME }}
# Endpoints
IBMCLOUD_PI_API_ENDPOINT: ${{ vars.IBMCLOUD_PI_API_ENDPOINT }}
IBMCLOUD_IAM_API_ENDPOINT: ${{ vars.IBMCLOUD_IAM_API_ENDPOINT }}
IBMCLOUD_RESOURCE_CATALOG_API_ENDPOINT: ${{ vars.IBMCLOUD_RESOURCE_CATALOG_API_ENDPOINT }}
IBMCLOUD_RESOURCE_MANAGEMENT_API_ENDPOINT: ${{ vars.IBMCLOUD_RESOURCE_MANAGEMENT_API_ENDPOINT }}
IBMCLOUD_RESOURCE_CONTROLLER_API_ENDPOINT: ${{ vars.IBMCLOUD_RESOURCE_CONTROLLER_API_ENDPOINT }}
IBMCLOUD_GS_API_ENDPOINT: ${{ vars.IBMCLOUD_GS_API_ENDPOINT }}
IBMCLOUD_GT_API_ENDPOINT: ${{ vars.IBMCLOUD_GT_API_ENDPOINT }}
# Power
PI_CLOUDINSTANCE_ID: ${{ secrets.PI_CLOUDINSTANCE_ID }}
IBMCLOUD_REGION: ${{ vars.IBMCLOUD_REGION }}
IBMCLOUD_ZONE: ${{ vars.IBMCLOUD_ZONE }}


# Step 7: Display Test Results
# - name: Display Test Results
# run: |
# echo "Test Results:"
# cat test-results/test-report.log
# if: always()
2 changes: 1 addition & 1 deletion ibm/acctest/acctest.go
Original file line number Diff line number Diff line change
Expand Up @@ -1074,7 +1074,7 @@ func init() {
// Added for Power Colo Testing
Pi_image = os.Getenv("PI_IMAGE")
if Pi_image == "" {
Pi_image = "c93dc4c6-e85a-4da2-9ea6-f24576256122"
Pi_image = "5b9568e5-8e39-420e-be63-a16cf7faa98e"
fmt.Println("[INFO] Set the environment variable PI_IMAGE for testing ibm_pi_image resource else it is set to default value '7200-03-03'")
}
Pi_sap_image = os.Getenv("PI_SAP_IMAGE")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (

func testAccCheckIBMPICatalogImagesDataSourceBasicConfig() string {
return fmt.Sprintf(`
data "ibm_pi_catalog_images" "power_catalog_images_basic" {
data "ibm_pi_catalog_images" "power_catalog_images_basic " {
pi_cloud_instance_id = "%s"
}`, acc.Pi_cloud_instance_id)
}
Expand Down
4 changes: 2 additions & 2 deletions ibm/service/power/data_source_ibm_pi_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func DataSourceIBMPIImage() *schema.Resource {
Schema: map[string]*schema.Schema{
// Arguments
Arg_CloudInstanceID: {
Description: "The GUID of the service instance associated with an account.",
Description: "The GUID of the service instance associated with an account .",
Required: true,
Type: schema.TypeString,
ValidateFunc: validation.NoZeroValues,
Expand Down Expand Up @@ -115,7 +115,7 @@ func dataSourceIBMPIImagesRead(ctx context.Context, d *schema.ResourceData, meta
d.Set(Attr_CRN, imagedata.Crn)
tags, err := flex.GetTagsUsingCRN(meta, string(imagedata.Crn))
if err != nil {
log.Printf("Error on get of pi image (%s) user_tags: %s", *imagedata.ImageID, err)
log.Printf("Error on get of pi image (%s) user_tags : %s", *imagedata.ImageID, err)
}
d.Set(Attr_UserTags, tags)
}
Expand Down
2 changes: 1 addition & 1 deletion ibm/service/power/data_source_ibm_pi_images.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func flattenStockImages(list []*models.ImageReference, meta interface{}) []map[s
tags, err := flex.GetTagsUsingCRN(meta, string(i.Crn))
if err != nil {
log.Printf(
"Error on get of image (%s) user_tags: %s", *i.ImageID, err)
"Error on get of image (%s) user_tags: %s", *i.ImageID, err)
}
l[Attr_UserTags] = tags
}
Expand Down
Loading