亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用 testcontainer-go 時遇到問題

使用 testcontainer-go 時遇到問題

Go
智慧大石 2023-05-22 17:45:55
我正在試用頁面示例https://github.com/testcontainers/testcontainer-gopackage mainimport (    "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 回答

?
MMTTMM

TA貢獻1869條經驗 獲得超4個贊

我也重現了這個問題,但我確實通過以下步驟構建并運行了測試:


my_package在樹之外創建一個目錄$GOPATH。

創建一個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)

}

go mod init mypackage


go test


查看完整回答
反對 回復 2023-05-22
  • 1 回答
  • 0 關注
  • 128 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號