Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Remove Needing To Use Script To Build Binary On Path #9

Open
irishgordo opened this issue Oct 27, 2022 · 0 comments
Open

Comments

@irishgordo
Copy link

irishgordo commented Oct 27, 2022

Description

  • Currently, there is the need for integration tests to have a script built on their path in order to test with integration tests.

https://github.com/harvester/vm-import-controller/blob/main/package/qemu-wrapper.sh

suse-workstation-team-harvester➜  vm-import-controller : main ✘ :✹✭ ᐅ  which qemu-wrapper.sh
/home/mike/.local/bin/qemu-wrapper.sh

It needs to be present and executable.

This seems like we could possibly shift this over to leverage, just building a temporary file, perhaps something like:

// maybe all these could also come from the environment too?
// like we could like try to do an os.Getenv("blah") - first, if there's nothing present, empty string or it comes in as something
// other than a string, we could default to something else, but then it would allow for having a top down 
// env based dependency injection on the function
// url: "https://raw.githubusercontent.com/harvester/vm-import-controller/main/package/qemu-wrapper.sh"
// folder: "/tmp"
// filename: qemu-wrapper.sh
func someFunc(folder string, url string, filename string) (err error){
    file, err := ioutil.TempFile(folder, filename)
    if err != nil {
        log.Fatal(err)
    }
    defer os.Remove(file.Name())
    // maybe just fetching the file from the repo, or we could have it exist somewhere else, this becomes network dependant tho
    // probably not the best solution
    resp, err := http.get(url)
    if err != nil {
        return err
    }
    defer resp.Body.Close()
    _, err = io.Copy(folder + "/" + filename, resp.Body)
   if err != nil {
      return err
   }
   /// do testing? - tho this becomes nested - but then the defers would clean everything up when we leave the scope of the func
}

And maybe just telling the test to look for the binary there at /tmp/qemu-wrapper.sh instead of on the path?
That would make it more hands off and the integration tests more ephemeral.

cc: @ibrokethecloud

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant