gruntwork-io / fetch

Download files, folders, and release assets from a specific git commit, branch, or tag of public and private GitHub repos.
https://www.gruntwork.io/
MIT License
587 stars 90 forks source link

Output release asset contents to standard output #103

Closed tonerdo closed 2 years ago

tonerdo commented 2 years ago

Description

An initial stab at supporting sending the contents of a downloaded asset to standard output

Documentation

TODOs

Please ensure all of these TODOs are completed before asking for a review.

Related Issues

Addresses #101

tonerdo commented 2 years ago

@robmorgan I agree on test cases and I spent some time thinking through them.. Any idea how to mock a cli.Context? That's my blocker.

robmorgan commented 2 years ago

@tonerdo you could try to create an integration test in integration_test.go with something like:

func TestFetchWithStdoutOption(t *testing.T) {
    tmpDownloadPath, err := ioutil.TempDir("", "fetch-stdout-test")
    require.NoError(t, err)

    repoUrl := "https://github.com/gruntwork-io/fetch-test-public"
    releaseTag := "v0.0.4"
    releaseAsset := "hello+world.txt"

    cmd := fmt.Sprintf("fetch --repo %s --tag %s --release-asset %s --stdout false %s", repoUrl, releaseTag, releaseAsset, tmpDownloadPath)
    t.Logf("Testing command: %s", cmd)
    stdoutput, _, err := runFetchCommandWithOutput(t, cmd)
    require.NoError(t, err)

    // Ensure the expected file was downloaded
    assert.FileExists(t, JoinPath(tmpDownloadPath, releaseAsset))

    // When --stdout is specified, ensure the file contents are piped to the standard output stream
    assert.Contains(t, stdoutput, "hello world")
}

Maybe if you do a loop with 2 test cases it might cover each code path?

tonerdo commented 2 years ago

Ah! Didn't realize we had integration tests. Thanks for the pointer