run-acceptance-tests

โดย hashicorp

ดำเนินการและวินิจฉัยการทดสอบการยอมรับ Go สำหรับผู้ให้บริการ Terraform พร้อมการแก้ไขปัญหาที่มีโครงสร้าง เรียกใช้การทดสอบการยอมรับที่เจาะจงโดยใช้ go test -run=TestAccFeatureHappyPath พร้อมตัวแปรสภาพแวดล้อม TF_ACC=1 วินิจฉัยความล้มเหลวแบบค่อยเป็นค่อยไป: ลองใหม่ด้วย -count=1 เปิดใช้งานเอาต์พุตแบบละเอียดด้วย -v เปิดใช้งานการบันทึกดีบักผ่าน TF_LOG=debug และคงพื้นที่ทำงาน Terraform ไว้ด้วย TF_ACC_WORKING_DIR_PERSIST=1 ตรวจสอบความน่าเชื่อถือของการทดสอบโดยจงใจทำให้ TestCheckFunc เสีย แล้วเรียกใช้การทดสอบอีกครั้งเพื่อ...

npx skills add https://github.com/hashicorp/agent-skills --skill run-acceptance-tests

An acceptance test is a Go test function with the prefix TestAcc.

Before running: acceptance tests create real infrastructure against the provider's live API, which may incur cost. Confirm the configured credentials point at a test account before proceeding.

To run a focused acceptance test named TestAccFeatureHappyPath:

  1. Run go test -run=TestAccFeatureHappyPath -timeout 60m with the following environment variables:

    • TF_ACC=1

    Default to non-verbose test output. Always pass an explicit -timeout: go test kills any test run after 10 minutes by default, and acceptance tests routinely exceed that.

  2. The acceptance tests may require additional environment variables for specific providers. To discover which ones:

    • Read the test's PreCheck / testAccPreCheck function and search the test files: grep -rn "os.Getenv" --include="*_test.go".
    • Check the repository's README, CONTRIBUTING, or .env.example for documented test setup.
    • The provider's Configure method shows how credentials are resolved; use the provider-configuration skill (if available) to understand a credential provider chain.

    Set the variables for the single test invocation (EXAMPLE_API_KEY=... TF_ACC=1 go test ...) rather than exporting them into the shell profile, and never write secret values into files inside the repository.

To diagnose a failing acceptance test, use these options, in order. These options are cumulative: each option includes all the options above it.

  1. Run the test again. Use the -count=1 option to ensure that go test does not use a cached result.
  2. Offer verbose go test output. Use the -v option.
  3. Offer debug-level logging. Enable debug-level logging with the environment variable TF_LOG=debug.
  4. Offer to persist the acceptance test's Terraform workspace. Enable persistence with the environment variable TF_ACC_WORKING_DIR_PERSIST=1.

A passing acceptance test may be a false negative. To "flip" a passing acceptance test named TestAccFeatureHappyPath:

  1. Edit the value of one of the TestCheckFuncs in one of the TestSteps in the TestCase.
  2. Run the acceptance test. Expect the test to fail.
  3. If the test fails, then undo the edit and report a successful flip. Else, keep the edit and report an unsuccessful flip.

If a test run is interrupted, real resources may be left behind; run the provider's sweepers if it registers them (see the provider-test-patterns skill's sweeper reference, if available). For writing or restructuring tests, use the provider-test-patterns skill.

Skills เพิ่มเติมจาก hashicorp

provider-framework-migration
hashicorp
ย้ายทรัพยากรและแหล่งข้อมูลของ Terraform provider จาก Plugin SDKv2 ไปยัง Plugin Framework: การรวมปลั๊กอินทั้งสองใน provider เดียวกัน (terraform-plugin-mux,…
provider-configuration
hashicorp
Implement การกำหนดค่าและรับรองความถูกต้องของ Terraform provider ด้วย Plugin Framework: provider schema สำหรับข้อมูลรับรอง (Optional + Sensitive attributes),…
provider-ephemeral-resources
hashicorp
ใช้ Terraform provider ephemeral resources กับ Plugin Framework: วงจรชีวิต Open/Renew/Close, การออกแบบ ephemeral schema, การลงทะเบียนผ่าน...
terraform-test
hashicorp
คู่มือที่ครอบคลุมสำหรับการเขียนและรันการทดสอบ Terraform พร้อมการยืนยันผล การจำลอง และการตรวจสอบโมดูล เขียนไฟล์ทดสอบโดยใช้ไวยากรณ์ .tftest.hcl พร้อมบล็อก run ที่ทำงานในโหมด plan หรือ apply รองรับการทำงานแบบลำดับและแบบขนานพร้อมการแยกสถานะที่เป็นทางเลือก ยืนยันเงื่อนไขบนแอตทริบิวต์ของทรัพยากร เอาต์พุต และแหล่งข้อมูล ใช้ expect_failures เพื่อตรวจสอบว่าอินพุตที่ไม่ถูกต้องถูกปฏิเสธอย่างเหมาะสม จำลองผู้ให้บริการ (Terraform 1.7.0+) เพื่อจำลองพฤติกรรมของโครงสร้างพื้นฐานโดยไม่ต้อง...
terraform-policy
hashicorp
เขียน ทดสอบ หรือแปลงไฟล์ Terraform Policy (.policy.hcl, .policytest.hcl, Sentinel→tfpolicy) ตัวกระตุ้น: policy.hcl, policytest, convert sentinel, tfpolicy,…
terraform-search-import
hashicorp
ค้นหาทรัพยากรคลาวด์ที่มีอยู่โดยใช้คำค้นหา Terraform Search และนำเข้าจำนวนมากเข้าสู่การจัดการ Terraform ใช้เมื่อนำโครงสร้างพื้นฐานที่ไม่ได้รับการจัดการเข้ามา…
aws-ami-builder
hashicorp
สร้าง Amazon Machine Images แบบกำหนดเองด้วย builder amazon-ebs ของ Packer อัตโนมัติการสร้าง AMI จาก AMI ต้นทางโดยใช้เทมเพลต HCL พร้อม provisioners สำหรับการปรับแต่ง (สคริปต์เชลล์, อัปโหลดไฟล์, การจัดการการกำหนดค่า) รองรับการกระจาย AMI หลายภูมิภาคผ่าน ami_regions และการกรอง AMI ต้นทางแบบยืดหยุ่นตามชื่อ, เจ้าของ, และประเภทการจำลองเสมือน ยืนยันตัวตนผ่านตัวแปรสภาพแวดล้อม, ไฟล์ข้อมูลรับรอง AWS, หรือโปรไฟล์อินสแตนซ์ IAM; รวมคำสั่งตรวจสอบและสร้างสำหรับเทมเพลต...
tfctl
hashicorp
โต้ตอบกับ HCP Terraform / Terraform Cloud / Terraform Enterprise โดยใช้ tfctl CLI ครอบคลุม API ทั้งหมด ใช้สำหรับ HCP Terraform หรือ Terraform Cloud หรือ…