英文:
Azure bicep testing with terratest fails
问题
我正在翻译以下内容:
我遇到了这样的问题:这是我用来测试是否创建了 Azure 资源的测试用例。
package test
import (
	"testing"
	"github.com/gruntwork-io/terratest/modules/azure"
	"github.com/stretchr/testify/assert"
)
func TestResourceGroupExists(t *testing.T) {
	resourceGroupName := "myResourceGroup"
	// 检查资源组是否存在
	exists, err := azure.ResourceGroupExistsE(t, resourceGroupName)
	// 断言没有错误并且资源组存在
	assert.NoError(t, err)
	assert.True(t, exists, "资源组不存在。")
}
当我通过以下命令执行此代码时:,我得到了以下错误:
./main_test.go:14:44: 无法将 t(类型为 *testing.T 的变量)作为 azure.ResourceGroupExistsE 的参数类型 string 使用
FAIL	terratest [构建失败]
我已经执行了以下命令来安装 Go 依赖项:。
英文:
I' having this kind of issue: This is my test case to test against azure resource created or no.
    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.")
}
and when I'm executing this code via such command: 
I get this kind of error:
    ./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]
I have executed this command for installing the go dependencies.
答案1
得分: 1
我用以下方式自己解决了这个问题:
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"
	// 检查资源组是否存在
	exists, err := azure.ResourceGroupExistsE(resourceGroupName, subscriptionID)
	// 断言没有错误并且资源组存在
	assert.NoError(t, err)
	assert.True(t, exists, "资源组不存在。")
}
希望对你有帮助!
英文:
I solved it by myself this way:
    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.")
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论