首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何安装Azure terratest模块

如何安装Azure terratest模块
EN

Stack Overflow用户
提问于 2021-07-14 09:38:19
回答 1查看 412关注 0票数 0

在安装azure模块时,我得到了以下错误。

代码:

代码语言:javascript
复制
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
}

执行:

代码语言:javascript
复制
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]

错误:

代码语言:javascript
复制
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

有人能帮我解决这个错误所需的更改吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-07-14 15:22:31

这个初始状态出发

代码语言:javascript
复制
-- 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来填充一组完整(但可能不兼容)的依赖项。

代码语言:javascript
复制
$ 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

代码语言:javascript
复制
$ 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是针对哪个版本编写的,我可以检查文件。在terratest v0.36.5,它指定

代码语言:javascript
复制
    github.com/Azure/azure-sdk-for-go v46.0.0+incompatible

所以让我们试试这个版本:

代码语言:javascript
复制
$ 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

代码语言:javascript
复制
$ 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来重新修复包图:

代码语言:javascript
复制
$ go mod tidy
go: downloading github.com/satori/go.uuid v1.2.0

这就是诀窍:

代码语言:javascript
复制
$ go build .

$
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68375626

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档