Go语言 Azure二头肌测试与terratest失败

gk7wooem  于 2023-08-01  发布在  Go
关注(0)|答案(1)|浏览(97)

我有这样的问题:这是我的测试用例,用于测试Azure资源是否已创建。

  1. package test
  2. import (
  3. "testing"
  4. "github.com/gruntwork-io/terratest/modules/azure"
  5. "github.com/stretchr/testify/assert"
  6. )
  7. func TestResourceGroupExists(t *testing.T) {
  8. resourceGroupName := "myResourceGroup"
  9. // Check if the resource group exists
  10. exists, err := azure.ResourceGroupExistsE(t, resourceGroupName)
  11. // Assert that there are no errors and the resource group exists
  12. assert.NoError(t, err)
  13. assert.True(t, exists, "Resource group does not exist.")
  14. }

字符串
当我通过这样的命令执行这段代码时:[go test -v]我得到这样的错误:

  1. ./main_test.go:14:44: cannot use t (variable of type *"testing".T) as type string in argument to azure.ResourceGroupExistsE
  2. FAIL terratest [build failed]


我已经执行了这个命令来安装go依赖项。[go mod tidy]

k5ifujac

k5ifujac1#

我自己是这样解决的:

  1. package test
  2. import (
  3. "github.com/gruntwork-io/terratest/modules/azure"
  4. "github.com/stretchr/testify/assert"
  5. "testing"
  6. )
  7. func TestResourceGroupExists(t *testing.T) {
  8. resourceGroupName := "azresourcegroup1"
  9. subscriptionID := "f01d4840-68b4-47bc-8906-4f1ab8f03342"
  10. // Check if the resource group exists
  11. exists, err := azure.ResourceGroupExistsE(resourceGroupName, subscriptionID)
  12. // Assert that there are no errors and the resource group exists
  13. assert.NoError(t, err)
  14. assert.True(t, exists, "Resource group does not exist.")
  15. }

字符串

展开查看全部

相关问题