【问题标题】:Go get problem when using testcontainer-go使用 testcontainer-go 时遇到问题
【发布时间】:2019-05-29 04:37:17
【问题描述】:

我正在试用页面示例https://github.com/testcontainers/testcontainer-go

package main

import (
    "context"
    "fmt"
    "net/http"
    "testing"

    testcontainer "github.com/testcontainers/testcontainer-go"
)

func TestNginxLatestReturn(t *testing.T) {
    ctx := context.Background()
    req := testcontainer.ContainerRequest{
        Image:        "nginx",
        ExposedPorts: []string{"80/tcp"},
    }
...
}

但是当我将代码放在<home>/go/src/my-sample 下的文件main.go 并调用go get 时,我就得到了这个错误:

#

 github.com/testcontainers/testcontainer-go
../github.com/testcontainers/testcontainer-go/docker.go:116:32: cannot use inspect.NetworkSettings.NetworkSettingsBase.Ports (type "github.com/docker/docker/vendor/github.com/docker/go-connections/nat".PortMap) as type "github.com/docker/go-connections/nat".PortMap in return argument
../github.com/testcontainers/testcontainer-go/docker.go:197:25: multiple-value uuid.NewV4() in single-value context
../github.com/testcontainers/testcontainer-go/docker.go:219:3: cannot use exposedPortSet (type map["github.com/docker/go-connections/nat".Port]struct {}) as type "github.com/docker/docker/vendor/github.com/docker/go-connections/nat".PortSet in field value
../github.com/testcontainers/testcontainer-go/docker.go:261:3: cannot use exposedPortMap (type map["github.com/docker/go-connections/nat".Port][]"github.com/docker/go-connections/nat".PortBinding) as type "github.com/docker/docker/vendor/github.com/docker/go-connections/nat".PortMap in field value

我做错了什么?

【问题讨论】:

    标签: go testcontainers


    【解决方案1】:

    我也重现了这个问题,但我确实通过以下步骤构建并运行了测试:

    1. $GOPATH 树之外创建一个my_package 目录。
    2. 创建一个mypackage_test.go 文件,内容如下:

      package main
      
      import (
          "testing"
      
          testcontainer "github.com/testcontainers/testcontainer-go"
      )
      
      func testNginxLatestReturn(t *testing.T) {
          req := testcontainer.ContainerRequest{
              Image:        "nginx",
              ExposedPorts: []string{"80/tcp"},
          }
          t.Log(req)
      }
      
    3. go mod init mypackage

    4. go test

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-02-21
      • 2021-11-08
      • 2014-01-08
      • 2011-03-09
      • 2013-01-30
      相关资源
      最近更新 更多