Search code examples
goamazon-s3go-testing

Send go test coverage output to stdout - send it to S3


I want to send the html for go test -c to stdout, so I can serve the resulting HTML from S3 static assets server.

Something like this:

arti_fact="s3://cm-html/cm-api/$commit_sha"

go test -coverprofile cover.out .
go tool cover -html=cover.out -o /dev/stdout  | aws s3 cp - "$arti_fact"

is there a way to write to stdout without using -o /dev/stdout?


Solution

  • I believe the way to send golang code coverage info to S3 / GCS is like so:

    go test -coverprofile cover.out .
    go tool cover -html=cover.out -o /dev/stdout  | gsutil cp - gs://my-bucket/foo
    

    if there is a way to do it without a temporary file, that would be nice. Something like:

    go test -coverprofile '/dev/stdout'  | 
    go tool cover -html='/dev/stdin' -o '/dev/stdout'  | 
    gsutil cp - 'gs://my-bucket/foo'