tebeka / go2xunit

Convert "go test" output to xunit compatible (used in Jenkins/Hudson)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

export a library API

tamird opened this issue · comments

Hi, thanks for the great tool!

I'd like to use your parser as a basis for https://github.com/2tvenom/go-test-teamcity, but for that I need a library API I can use, particularly for the parsing of go test output.

Would you be willing to expose such an API?

Hi @tamird,

A refactor of go2xunit is something I'm think of for a while. Sadly I'm super swamped so breaking do this will take a bit of time. I also want to make sure that I create the right API since currently the data structures are for internal use.

Another approach will be to merge go-test-teamcity into go2xunit as another output format (the way we currently have -xunitnet flag). This will be simpler since it's just adding another output template (see xmlout.go). Are you willing to consider such a solution? (I'd also love the extra help with go2xunit).

Thanks - Miki

Another approach will be to merge go-test-teamcity into go2xunit as another output format (the way we currently have -xunitnet flag). This will be simpler since it's just adding another output template (see xmlout.go). Are you willing to consider such a solution? (I'd also love the extra help with go2xunit).

That will be somewhat helpful, but not quite all the way; I also have https://github.com/cockroachdb/build-utils/blob/master/cmd/post-github/main.go which I use to post github issues when tests fail, and that needs some special logic which needs a library. :(

OK. I'll work on refactoring and exposing an API. Hopefully I'll have some time soon.

@tamird You can now "import github.com/tebeka/go2xunit/lib" and use parsers from there. Still experimental - LMK what you think of the API.

@tebeka thanks! one concern I have with the current API is that it parses all the input before yielding control - this prevents streaming output from any tools written with it :(

@tamird The input is usually small so this is not an issue. I plan to refactor the parsers but don't think I'll get to incremental parsing (SAX style). For pipes you can do something like:

package main

import (
    "fmt"
    "io"
    "log"
    "os/exec"

    "github.com/tebeka/go2xunit/lib"
)

func main() {
    rdr, wtr := io.Pipe()
    cmd := exec.Command("go", "test", "-v")
    cmd.Stdout = wtr
    go func() {
        cmd.Run()
        wtr.Close()
    }()

    suites, err := lib.ParseGotest(rdr, "")
    if err != nil {
        log.Fatalf("error: can't parse - %s", err)
    }
    fmt.Printf("Total of %d suites\n", len(suites))
}

Hey @tebeka - thanks for the great work on this tool!

I'd like to second @tamird's point about the streaming style. Certain CI tools can incrementally report on the progress of tests by parsing a pipe of formatted test output. We use TeamCity, which has this capability. We're currently using go-test-teamcity, which does provide a streaming translation of Go test output to TeamCity-style test input, but isn't quite as robust as go2xunit or the library you've made. We'd like to port go-test-teamcity to using this library, but we can't so long as it doesn't support streaming output.

Hi @jordanlewis,

Thanks for the input. I've opened #41 and we'll continue there.

It's not a matter of size - in our use case, we are piping our test output
through go-test-teamcity and then it is picked up by teamcity - it's nice
to have streaming output in CI.

On Tue, Oct 18, 2016 at 1:10 AM, Miki Tebeka notifications@github.com
wrote:

@tamird https://github.com/tamird The input is usually small so this is
not an issue. I plan to refactor the parsers but don't think I'll get to
incremental parsing (SAX style). For pipes you can do something like:

package main
import (
"fmt"
"io"
"log"
"os/exec"

"github.com/tebeka/go2xunit/lib"

)
func main() {
rdr, wtr := io.Pipe()
cmd := exec.Command("go", "test", "-v")
cmd.Stdout = wtr
go func() {
cmd.Run()
wtr.Close()
}()

suites, err := lib.ParseGotest(rdr, "")
if err != nil {
    log.Fatalf("error: can't parse - %s", err)
}
fmt.Printf("Total of %d suites\n", len(suites))

}


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#39 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/ABdsPKvpWnCPWSsrO7XbaKe4UxdFgpeYks5q1FTUgaJpZM4KWGhL
.

@tamird See my comment on #41