拨号 tcp:协议不可用 go webassembly test [英] dial tcp: Protocol not available go webassembly test

查看:60
本文介绍了拨号 tcp:协议不可用 go webassembly test的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

试图去测试一个触发 POST 请求的网络组装函数.

Attempting to go test a web-assembly function which fires an POST request.

收到以下错误:

firePing_test.go:40: ERROR ON POST REQUEST: Post https://not-the-real-api.execute-api.us-east-1.amazonaws.com/testing: dial tcp: Protocol not available

运行:Ubuntu 18.04.2 LTSgo 版本 go1.12.2 linux/amd64

Running: Ubuntu 18.04.2 LTS go version go1.12.2 linux/amd64

我已经测试过该函数是有效的,并且会在 chrome 中执行时发送请求.为 linux/amd64 编译时测试也通过.

I've tested that the function is valid and will send a request when executing in chrome. Test also passes when compiled for linux/amd64.

问题函数:

// FirePing fires a ping
func FirePing(protocol *string, domain *string, params *map[string]string) (*http.Response, error) {

    // Marshal map into POST request body
    reqBody, err := json.Marshal(*params)
    if err != nil {
        return  nil, fmt.Errorf("ERROR ON MARSHAL OF PARAMS: %v", err)
    }

    // Send POST request
    req, err := http.NewRequest("POST", *protocol + "://" + *domain, bytes.NewBuffer(reqBody))
    if err != nil {
        return  nil, fmt.Errorf("ERROR ON FORMING REQUEST: %v", err)
    }
    client := &http.Client{}
    resp, err := client.Do(req)
    if err != nil {
        return nil,fmt.Errorf("ERROR ON POST REQUEST: %v",err)
    }

    return resp, nil
}

问题测试函数调用:

// FirePing and receive response
    resp, err := FirePing(&config.Config.Protocol, &config.Config.Domain, &m)
    if err != nil {
        t.Error(err)
        return
    }

应该通过这个测试用例,因为它在浏览器中很好地执行了函数调用.

Should pass this test case as it performs the function call fine in the browser.

我唯一见过的其他地方是:

Only other place I have seen this is:

http.Get 返回协议不可用错误

哪个接缝来自禁用 tcp 连接的操场.我在本地运行这个测试

Which seams to be from playground disabling tcp connections. I am running this test locally

推荐答案

MVP 版本专门针对在浏览器中运行 WASM.因此,浏览器 API 不允许任意 TCP/IP 连接,因此 WASM 也同样受到限制.也就是说,WASM 一直有超越浏览器的雄心.名为 WASI 的最新倡议将添加需要在浏览器之外使用的功能,例如文件 I/O 和网络原语.

The MVP release was exclusively targeting running WASM in the browser. As such, the browser APIs do not allow arbitrary TCP/IP connections and therefore WASM is equally limited. That said, WASM has always had ambitions to go beyond the browser. The latest initiative called WASI will add features required to be used outside the browser, like File I/O and networking primitives.

这篇关于拨号 tcp:协议不可用 go webassembly test的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆