如何安装Azure terratest模块

huangapple go评论70阅读模式
英文:

How to install Azure terratest module

问题

我在安装 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

有人可以帮我看看需要做哪些更改才能解决这个错误吗?

英文:

I am getting the following error while installing azure module.

code:

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
}

Execution:

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]

Error:

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

Can someone help me as to what changes required to get rid of this error?

答案1

得分: 1

这个初始状态开始:

-- 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是针对哪个版本编写的,我可以检查它的go.mod文件。在terratestv0.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 .

$
英文:

Starting out from 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

First, run go mod tidy to fill in a complete (but perhaps incompatible) set of dependencies.

$ 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

Now try 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
…

It produces lots of errors, which isn't entirely unexpected: azure-sdk-for-go is on major version 55(!), which to me indicates a high rate of breaking changes. So probably this version of terratest was written against an older version, and has been broken by some intervening change.


To figure out which version terratest is written against, I can check its go.mod file. At terratest v0.36.5, it specifies

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

So let's try that version:

$ 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

Now go build again:

$ 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

This is because I told go get to download a specific version of a module, but I actually need a set of packages from within that module — and I'm missing checksums for some of the dependencies of those packages. So I'll run go mod tidy to fix up the package graph again:

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

And that does the trick:

$ go build .

$

huangapple
  • 本文由 发表于 2021年7月14日 17:38:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/68375626.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定