Unbabel / replicant

Synthetic application testing made easy, written in Go.
Apache License 2.0
17 stars 5 forks source link

Unable to import Google's protobuf libs #23

Open flaviofernandes004 opened 4 years ago

flaviofernandes004 commented 4 years ago

Describe the bug I'm unable to import the protobuf libraries developed by Google which is a basic requirement to develop test that have the the protobuf generated code inside.

To Reproduce Steps to reproduce the behavior:

  1. Run Replicant v0.2.1
  2. Copy the Go example presented in the Readme
  3. Add the import for the proto libs
  4. Invoke the /api/v1/run
  5. Observe the "error": "driver/go: error initializing transaction script: 9:3: import \"github.com/golang/protobuf/proto\" error: unable to find source related to: \"github.com/golang/protobuf/proto\""

Expected behavior i expected Replicant to detect and fetch the dependencies so that it could run such tests.

Screenshots The response image

The request payload

name: duckduckgo-api-search
driver: go
schedule: '@every 60s'
timeout: 60s
retry_count: 2
inputs:
  url: "https://api.duckduckgo.com"
  text: "blade runner"
metadata:
  transaction: api-search
  application: duckduckgo
  environment: production
  component: api
script: |
  package transaction

  // Code generated by protoc-gen-go. DO NOT EDIT.
  // source: translation.proto

  import (
    context "context"
    fmt "fmt"
    proto "github.com/golang/protobuf/proto"
    grpc "google.golang.org/grpc"
    codes "google.golang.org/grpc/codes"
    status "google.golang.org/grpc/status"
    math "math"
    "bytes"
    "context"
    "fmt"
    "net/http"
    "io/ioutil"
    "net/http"
    "regexp"
  )

  //The protobuf generated code is omitted due to business reasons

  func Run(ctx context.Context) (m string, d string, err error) {
    req, err := http.NewRequest(http.MethodGet, "{{ index . "url" }}", nil)
      if err != nil {
        return "request build failed", "", err
    }
    req.Header.Add("Accept-Charset","utf-8")
    q := req.URL.Query()
    q.Add("q", "{{ index . "text" }}")
    q.Add("format", "json")
    q.Add("pretty", "1")
    q.Add("no_redirect", "1")
    req.URL.RawQuery = q.Encode()
    client := &http.Client{}
    resp, err := client.Do(req)
    if err != nil {
      return "failed to send request", "", err
    }
    buf, err := ioutil.ReadAll(resp.Body)
    if err != nil {
      return "failed to read response", "", err
    }
    rx, err := regexp.Compile(`"Text"\s*:\s*"(.*?)"`)
    if err != nil {
      return "failed to compile regexp", "", err
    }
    s := rx.FindSubmatch(buf)
    if len(s) < 2 {
      return "failed to find data", "", fmt.Errorf("no match")
    }
    return "search result", fmt.Sprintf("%s", s[1]), nil
  }
Gisson commented 4 years ago

@flaviofernandes004 I can look into this if @brunotm can assign me :smile:

flaviofernandes004 commented 4 years ago

I have already an issue in my sprint to address this problem xD

Gisson commented 4 years ago

https://github.com/containous/yaegi/issues/469 for reference

flaviofernandes004 commented 4 years ago

Thx 💪 . So for you to have more context, we are planning extending the CLI to allow one to register compiled tests and having Replicant executing those using the plugin package

Gisson commented 4 years ago

Ok, then I had no idea. You guys go on and solve this then :wink: