如何安装 Azure terratest 模块

如何解决如何安装 Azure terratest 模块

我在安装 azure 模块时收到以下错误

代码

package test

import (
    "testing"
    "github.com/Azure/azure-sdk-for-go/profiles/latest/cosmos-db/mgmt/documentdb"
    "github.com/gruntwork-io/terratest/modules/azure"
    "github.com/stretchr/testify/assert"
)

func TestterraformAzureCosmosDBExample(t *testing.T) {
    foo
    boo
}

执行:

C:\foo\boo>go test -v
# foo_test
foo_test.go:6:2: no required module provides package github.com/gruntwork-io/terratest/modules/azure; to add it:
        go get github.com/gruntwork-io/terratest/modules/azure
FAIL    foo_test [setup Failed]

错误

C:\foo\boo>go get github.com/gruntwork-io/terratest/modules/azure
# github.com/gruntwork-io/terratest/modules/azure
C:\foo\go\pkg\mod\github.com\gruntwork-io\terratest@v0.36.5\modules\azure\keyvault.go:139:50: too many arguments in call to "github.com/Azure/azure-sdk-for-go/services/keyvault/auth".NewAuthorizerFromFile
        have (string)
        want ()
C:\foo\go\pkg\mod\github.com\gruntwork-io\terratest@v0.36.5\modules\azure\resourcegroup.go:78:9: cannot use &rg (type *"github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2020-10-01/resources".Group) as type *"github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2020-06-01/resources".Group in return argument
C:\foo\go\pkg\mod\github.com\gruntwork-io\terratest@v0.36.5\modules\azure\resourcegroup.go:100:18: cannot use rg.Values() (type []"github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2020-10-01/resources".Group) as type []"github.com/Azure/azure-sdk-for-go/services/resources/mgmt/2020-06-01/resources".Group in return argument

有人可以帮助我了解消除此错误所需的更改吗?

解决方法

this initial state开始:

-- main.go --
package main

import (
    _ "github.com/Azure/azure-sdk-for-go/profiles/latest/cosmos-db/mgmt/documentdb"
    _ "github.com/gruntwork-io/terratest/modules/azure"
    _ "github.com/stretchr/testify/assert"
)

func main() {}
-- go.mod --
module example.com/m

go 1.17

首先,运行 go mod tidy 以填充完整(但可能不兼容)的依赖项集。

$ go mod tidy
go: finding module for package github.com/stretchr/testify/assert
go: finding module for package github.com/Azure/azure-sdk-for-go/profiles/latest/cosmos-db/mgmt/documentdb
go: finding module for package github.com/gruntwork-io/terratest/modules/azure
go: found github.com/Azure/azure-sdk-for-go/profiles/latest/cosmos-db/mgmt/documentdb in github.com/Azure/azure-sdk-for-go v55.6.0+incompatible
go: found github.com/gruntwork-io/terratest/modules/azure in github.com/gruntwork-io/terratest v0.36.5
go: found github.com/stretchr/testify/assert in github.com/stretchr/testify v1.7.0
go: finding module for package github.com/gofrs/uuid
go: found github.com/gofrs/uuid in github.com/gofrs/uuid v4.0.0+incompatible

现在试试go build

$ go build .
# github.com/Azure/azure-sdk-for-go/services/mysql/mgmt/2020-01-01/mysql
.gopath/pkg/mod/github.com/!azure/azure-sdk-for-go@v55.6.0+incompatible/services/mysql/mgmt/2020-01-01/mysql/models.go:346:2: undefined: azure.FutureAPI
…

它产生了很多错误,这并不完全出乎意料:azure-sdk-for-go 在主要版本 55(!) 上,对我来说这表明破坏性更改的比率很高。因此,此版本的 terratest 可能是针对旧版本编写的,并且已被一些干预性更改破坏。


要确定 terratest 是针对哪个版本编写的,我可以检查 its go.mod file。在 terratest v0.36.5,它指定

    github.com/Azure/azure-sdk-for-go v46.0.0+incompatible

让我们试试那个版本:

$ go get -d github.com/Azure/azure-sdk-for-go@v46.0.0+incompatible
go: downloading github.com/Azure/azure-sdk-for-go v46.0.0+incompatible
go get: downgraded github.com/Azure/azure-sdk-for-go v55.6.0+incompatible => v46.0.0+incompatible

现在又go build

$ go build .
.gopath/pkg/mod/github.com/!azure/azure-sdk-for-go@v46.0.0+incompatible/services/mysql/mgmt/2020-01-01/mysql/models.go:28:2: missing go.sum entry for module providing package github.com/satori/go.uuid (imported by github.com/Azure/azure-sdk-for-go/services/keyvault/mgmt/2016-10-01/keyvault); to add:
        go get github.com/Azure/azure-sdk-for-go/services/keyvault/mgmt/2016-10-01/keyvault@v46.0.0+incompatible

这是因为我告诉 go get 下载模块的特定版本,但我实际上需要该模块中的一组 — 并且我缺少这些包的某些依赖项的校验和。所以我将再次运行 go mod tidy 来修复包图:

$ go mod tidy
go: downloading github.com/satori/go.uuid v1.2.0

这就是诀窍:

$ go build .

$
,

您使用过 go mod initgo mod tidy 了吗?

当你使用外部包时,你必须创建 .mods 来生成你程序的完整环境

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?
Java在半透明框架/面板/组件上重新绘画。
Java“ Class.forName()”和“ Class.forName()。newInstance()”之间有什么区别?
在此环境中不提供编译器。也许是在JRE而不是JDK上运行?
Java用相同的方法在一个类中实现两个接口。哪种接口方法被覆盖?
Java 什么是Runtime.getRuntime()。totalMemory()和freeMemory()?
java.library.path中的java.lang.UnsatisfiedLinkError否*****。dll
JavaFX“位置是必需的。” 即使在同一包装中
Java 导入两个具有相同名称的类。怎么处理?
Java 是否应该在HttpServletResponse.getOutputStream()/。getWriter()上调用.close()?
Java RegEx元字符(。)和普通点?