run-acceptance-tests

作者: hashicorp

We need to translate the given text from English to Traditional Chinese. The text is about executing and diagnosing Go acceptance tests for Terraform providers. We must preserve product names, protocol names, URLs, numbers, technical terms. The name "run-acceptance-tests" is not in the text, so we don't include it. We should not add any extra commentary or labels. The text: "Execute and diagnose Go acceptance tests for Terraform providers with structured troubleshooting. Run focused acceptance tests using go test -run=TestAccFeatureHappyPath with TF_ACC=1 environment variable Diagnose failures progressively: retry with -count=1 , enable verbose output with -v , activate debug logging via TF_LOG=debug , and persist Terraform workspace with TF_ACC_WORKING_DIR_PERSIST=1 Validate test reliability by intentionally breaking a TestCheckFunc, re-running the test to..." We need to translate this into Traditional Chinese. Keep technical terms like "go test", "TF_ACC=1", "-count=1", "-v", "TF_LOG=debug",

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.

來自 hashicorp 的更多技能

provider-actions
hashicorp
使用 Plugin Framework 實作 Terraform Provider 動作。在開發於生命週期事件(之前/之後…)執行的命令式操作時使用。
official
new-terraform-provider
hashicorp
在新版Terraform Provider使用Plugin Framework建立框架時使用此功能:工作區佈局、Go模組設定、Provider伺服器main.go,以及provider.go…
official
terraform-test
hashicorp
編寫和執行 Terraform 測試的綜合指南。在建立測試檔案(.tftest.hcl)、使用 run 區塊編寫測試情境、驗證…時使用。
official
terraform-test
hashicorp
撰寫與執行 Terraform 測試的完整指南,涵蓋斷言、模擬及模組驗證。使用 .tftest.hcl 語法編寫測試檔案,透過 run 區塊在 plan 或 apply 模式下執行,支援順序與平行執行,並可選擇隔離狀態。對資源屬性、輸出及資料來源進行條件斷言;使用 expect_failures 驗證無效輸入是否被正確拒絕。模擬提供者(Terraform 1.7.0 以上版本)可模擬基礎設施行為,無需...
official
provider-actions
hashicorp
使用 Plugin Framework 在資源生命週期事件中執行命令式的 Terraform Provider 動作。支援建立前/後與更新前/後的觸發機制(Terraform 1.14.0 不支援銷毀事件)。需以正確的框架類型、集合的 ElementType 及輸入驗證器定義適當的綱要。包含進度回報、逾時管理及長時間操作的全面錯誤處理。實作輪詢與...
official
aws-ami-builder
hashicorp
使用Packer的amazon-ebs建置器建立自訂Amazon Machine Images。透過HCL範本自動化從來源AMI建立AMI,並搭配佈建工具(Shell腳本、檔案上傳、組態管理)進行自訂。支援透過ami_regions進行多區域AMI分發,以及依名稱、擁有者和虛擬化類型進行靈活的來源AMI篩選。可透過環境變數、AWS憑證檔案或IAM執行個體設定檔進行驗證;包含範本的驗證與建置命令...
official
new-terraform-provider
hashicorp
使用 Plugin Framework 建立新的 Terraform provider。生成新的 Go 模組工作區,採用標準的「terraform-provider-」命名慣例,並初始化所需的依賴項。提供遵循 HashiCorp Plugin Framework 模式的範本 main.go 檔案,並附有待辦事項標記供自訂使用。透過執行建置與測試指令來驗證設定,確保 provider 能成功編譯並通過初步檢查。在建立新的工作區前,會先確認意圖以管理工作區。
official
azure-verified-modules
hashicorp
認證要求與Azure Terraform模組尋求AVM合規性的最佳實踐。強制執行提供者版本限制(azurerm >= 4.0, < 5.0;azapi >= 2.0, < 3.0),並禁止基於git的模組引用,改為使用固定的Terraform註冊表來源。要求所有識別碼採用小寫蛇形命名法、精確的變數類型、透過防腐層模式實現離散的輸出屬性,以及按字母順序排列的locals。新增資源時需要功能切換變數...
official