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 #183

Draft
wants to merge 34 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
038fb8b
Acceptance test
michaelkad Dec 4, 2024
c4eae47
Acceptance test: update directory
michaelkad Dec 4, 2024
df88a55
Acceptance test: fetch origin
michaelkad Dec 4, 2024
9badfe5
Acceptance test: update env vars
michaelkad Dec 4, 2024
5963c36
Acceptance test: fix env vars
michaelkad Dec 4, 2024
6957ad2
Acceptance test: add missing env vars
michaelkad Dec 4, 2024
cbc046a
Acceptance test: remove tf log
michaelkad Dec 4, 2024
1ff1825
Acceptance test: update accpt test file
michaelkad Dec 4, 2024
03ba601
Acceptance test: printing test run log
michaelkad Dec 4, 2024
1df9220
Acceptance test: printing test run log 2
michaelkad Dec 4, 2024
7443276
Acceptance test: cleaning output
michaelkad Dec 4, 2024
76dd009
Acceptance test: add check for powervs only
michaelkad Dec 4, 2024
6c58c96
Acceptance test: test missing variables
michaelkad Dec 5, 2024
f7bb535
Acceptance test: remove resource update
michaelkad Dec 5, 2024
ac0fa11
Acceptance test: fix display result
michaelkad Dec 5, 2024
0e2467c
Acceptance test: fix display result 2
michaelkad Dec 5, 2024
6da9d43
Acceptance test: fix display result 3
michaelkad Dec 5, 2024
8a9e7a0
Acceptance test: fix display result 4
michaelkad Dec 6, 2024
580f545
Acceptance test: fix display result 5
michaelkad Dec 6, 2024
b49054b
Acceptance test: fix display result 6
michaelkad Dec 6, 2024
a622dda
Acceptance test: fix display result 7
michaelkad Dec 6, 2024
fac1d08
Acceptance test: fix display result 8
michaelkad Dec 6, 2024
cddcf8f
Acceptance test: fix display result 9
michaelkad Dec 6, 2024
3a877e1
Acceptance test: fix display result 10
michaelkad Dec 6, 2024
c86579b
Acceptance test: Add repo to secret
michaelkad Dec 9, 2024
0aeccfa
Acceptance test: update modified test files
michaelkad Dec 9, 2024
bfde6c5
Acceptance test: change test file
michaelkad Dec 9, 2024
eabd443
Acceptance test: update repo
michaelkad Dec 9, 2024
f9dc387
Acceptance test: update repo 2
michaelkad Dec 9, 2024
ebb8c21
Acceptance test: update repo 3
michaelkad Dec 9, 2024
eeaa2c9
Acceptance test: update repo 4
michaelkad Dec 9, 2024
7f36d4c
Acceptance test: update repo 5
michaelkad Dec 9, 2024
a0c6afc
Acceptance test: update repo 6
michaelkad Dec 9, 2024
38e6531
Acceptance test: update repo 7
michaelkad Dec 9, 2024
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
118 changes: 118 additions & 0 deletions .github/workflows/power-acceptance-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
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 : Find modified files, set environment variables, and run tests
- name: Find modified files and run acceptance tests
run: |
# Process test files
mkdir -p test-results
declare -A modified_test_files_map
# Get the list of modified Go files in the PR under the ibm/service/power directory
git fetch origin -q
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

echo "Processing file: $file"
if [[ "$file" == *_test.go ]]; then
echo "Adding $file to the list map"
modified_test_files_map["$file"]=1
else

# 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_map["$test_file"]=1
fi
fi
done

# If there are modified test files, run the tests
if [ ${#modified_test_files_map[@]} -gt 0 ]; then
modified_test_files=$(echo "${!modified_test_files_map[@]}")
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
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: ${{ secrets.IBMCLOUD_REGION }}
IBMCLOUD_ZONE: ${{ secrets.IBMCLOUD_ZONE }}


# Step 6: Display Test Results
- name: Display Test Results
run: |
echo "Test Results:"
grep -E '^(=== RUN|--- PASS|--- FAIL|PASS|FAIL)' 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 @@ -74,6 +74,7 @@ func TestAccIBMPICatalogImagesDataSourceSAP(t *testing.T) {
})
}

// VTL test
func TestAccIBMPICatalogImagesDataSourceVTL(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { acc.TestAccPreCheck(t) },
Expand Down
2 changes: 1 addition & 1 deletion ibm/service/power/data_source_ibm_pi_image.go
Original file line number Diff line number Diff line change
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
1 change: 1 addition & 0 deletions ibm/service/power/data_source_ibm_pi_images_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func TestAccIBMPIImagesDataSource_basic(t *testing.T) {
})
}

// testAccCheckIBMPIImagesDataSourceConfig returns the Terraform configuration for checking IBM Cloud Images data source.
func testAccCheckIBMPIImagesDataSourceConfig() string {
return fmt.Sprintf(`
data "ibm_pi_images" "testacc_ds_image" {
Expand Down
Loading