samedi 27 avril 2019

dial tcp: Protocol not available go webassembly test

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

Receive the following error:

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

Running: Ubuntu 18.04.2 LTS go version go1.12.2 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.

Problem Function:

// 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
}

Problem Test Function Call:

// 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 returns Protocol not available error

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

Aucun commentaire:

Enregistrer un commentaire