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

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

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

package test

import (
    "testing"
    "github.com/gruntwork-io/terratest/modules/azure"
    "github.com/stretchr/testify/assert"
)

func TestResourceGroupExists(t *testing.T) {
    resourceGroupName := "myResourceGroup"

    // Check if the resource group exists
    exists, err := azure.ResourceGroupExistsE(t, resourceGroupName)

    // Assert that there are no errors and the resource group exists
    assert.NoError(t, err)
    assert.True(t, exists, "Resource group does not exist.")
}

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

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


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

k5ifujac

k5ifujac1#

我自己是这样解决的:

package test

import (
    "github.com/gruntwork-io/terratest/modules/azure"
    "github.com/stretchr/testify/assert"
    "testing"
)

func TestResourceGroupExists(t *testing.T) {
    resourceGroupName := "azresourcegroup1"
    subscriptionID := "f01d4840-68b4-47bc-8906-4f1ab8f03342"

    // Check if the resource group exists
    exists, err := azure.ResourceGroupExistsE(resourceGroupName, subscriptionID)

    // Assert that there are no errors and the resource group exists
    assert.NoError(t, err)
    assert.True(t, exists, "Resource group does not exist.")
}

字符串

相关问题