Перейти получить проблему при использовании testcontainer-go - PullRequest
0 голосов
/ 02 января 2019

Я пробовал образец страницы 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"},
    }
...
}

но когда я помещаю код в файл main.go под <home>/go/src/my-sample и вызываю 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

Что я делаю не так?

1 Ответ

0 голосов
/ 02 января 2019

Я также воспроизвел проблему, но мне удалось построить и запустить тест, выполнив следующие шаги:

  1. Создайте каталог my_package вне дерева $GOPATH.
  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
...