Skip to content

Commit

Permalink
initial vgt version
Browse files Browse the repository at this point in the history
  • Loading branch information
roblaszczak committed Sep 21, 2024
0 parents commit b6fdea4
Show file tree
Hide file tree
Showing 24 changed files with 498,649 additions and 0 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Test

on:
push:
branches: [ main ]
pull_request:

jobs:

test:
name: Run Tests
runs-on: ubuntu-latest

steps:
- name: Check out code
uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.23'

- name: Get dependencies
run: go mod download

- name: Run tests
run: go test -v ./...
Empty file added .gitignore
Empty file.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Robert Laszczak

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
78 changes: 78 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# vgt - Visualise Go Test

`vgt` is a tool for visualising Go test results in a browser.

[//]: # ([todo - logo])

It's helpful with understanding parallelism of tests and identifying slow tests.
More information can be found in the [TODO] blog post.

![Screenshot 1](docs/img1.png)
![Screenshot 2](docs/img2.png)

## Installation

```
go install -u github.com/roblaszczak/vgt
```

You can also run without installing by running `go run github.com/roblaszczak/vgt@latest`.

## Usage

For visualising test results, run `go test` with the `-json` flag and pipe the output to `vgt`.

```
go test -json ./... | vgt
```

or with `go run`:

```
go test -json ./... | go run github.com/roblaszczak/vgt@latest
```

After tests were executed, a browser window will open with the visualisation.

If you want to preserve the output, you can pipe test logs to file and later pass it to `vgt`:

```
go test -json ./... > test.json
cat test.json | vgt
```


### Additional flags

```
Usage of vgt:
-debug
enable debug mode
-duration-cutoff string
threshold for test duration cutoff, under which tests are not shown in the chart (default "100µs")
-keep-running
keep browser running after page was opened
-pass-output
pass output received to stdout (default true)
-print-html
print html to stdout instead of opening browser
```

## Development

If you have an idea for a feature or found a bug, feel free to open an issue or a pull request.

Before making a big change, it's a good idea to open an issue to discuss it first.

### Running tests

Tests are not really sophisticated, and are based on checking changes in golden files and checking in browser if
it looks good.

### Updating golden files

If you made a change and want to update golden files, you can run:

```
go test . -update-golden
```
83 changes: 83 additions & 0 deletions chart.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package main

import (
"fmt"
"log/slog"
"strings"
"time"
)

func generateCharts(pr ParseResult) []PlotlyChart {
var charts []PlotlyChart

testNames := pr.TestNamesOrderedByStart()

for _, tn := range testNames {
ch := PlotlyChart{
Type: "bar",
Orientation: "h",
Hoverinfo: "text",
Textposition: "inside",
}

pause, hasPause := pr.TestPauses.ByTestName(tn)
run, hasRun := pr.TestRuns.ByTestName(tn)

if !hasRun {
slog.Debug("Test was not executed", "test", tn)
continue
}

packageNameParts := strings.Split(tn.Package, "/")

var packageName string
if len(packageNameParts) != 0 {
packageName = packageNameParts[len(packageNameParts)-1]
} else {
slog.Warn("Package name is empty", "test", tn.Package)
}

packageNameFull := fmt.Sprintf("%s.%s", packageName, tn.TestName)
y := packageNameFull

if !run.Passed {
y += " (failed)"
}

if hasPause {
startAfter := pause.Start.Sub(pr.Start)
duration := pause.Duration()

slog.Debug("Test was paused", "startAfter", startAfter, "duration", duration, "test", tn)

ch.Add(
fmt.Sprintf("%s pause (%s)", packageNameFull, duration.Round(time.Millisecond).String()),
y,
startAfter,
duration,
"rgba(108,122,137,1)",
)
}

{
startAfter := run.Start.Sub(pr.Start)
duration := run.Duration()

slog.Debug("Test was executed", "startAfter", startAfter, "duration", duration, "test", tn)

ch.Add(
fmt.Sprintf("%s run (%s)", packageNameFull, duration.Round(time.Millisecond)),
y,
startAfter,
duration,
durationToRgb(run, pr.MaxDuration),
)
}

slog.Debug("PlotlyChart", "chart", ch)

charts = append(charts, ch)
}

return charts
}
Binary file added docs/img1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/img2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module github.com/roblaszczak/vgt

go 1.22

require (
github.com/lmittmann/tint v1.0.5
github.com/muesli/cancelreader v0.2.2
github.com/stretchr/testify v1.9.0
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/sys v0.0.0-20220204135822-1c1b9b1eba6a // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
16 changes: 16 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/lmittmann/tint v1.0.5 h1:NQclAutOfYsqs2F1Lenue6OoWCajs5wJcP3DfWVpePw=
github.com/lmittmann/tint v1.0.5/go.mod h1:HIS3gSy7qNwGCj+5oRjAutErFBl4BzdQP6cJZ0NfMwE=
github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA=
github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
golang.org/x/sys v0.0.0-20220204135822-1c1b9b1eba6a h1:ppl5mZgokTT8uPkmYOyEUmPTr3ypaKkg5eFOGrAmxxE=
golang.org/x/sys v0.0.0-20220204135822-1c1b9b1eba6a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Loading

0 comments on commit b6fdea4

Please sign in to comment.