Skip to content

Commit

Permalink
(feat) added benchmarks for a simple Go installation
Browse files Browse the repository at this point in the history
  • Loading branch information
kevincobain2000 committed Apr 6, 2024
1 parent ba3e176 commit 2feeae8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
7 changes: 7 additions & 0 deletions .github/workflows/coveritup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ jobs:
type: unit-test-run-time
command: go test -race -v ./... -count=1 -coverprofile=coverage.out
record: runtime
- name: Benchmark Test
uses: kevincobain2000/action-coveritup@v2
with:
type: allocs-per-op
command: go test -count 2 -bench=. ./... -benchmem|grep "allocs"|tail -1|awk '{print $7}'
record: score
metric: alloc

- name: Coverage
run: gocov convert coverage.out | gocov-xml > coverage.xml
Expand Down
13 changes: 12 additions & 1 deletion gobrew_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/stretchr/testify/assert"
)

func setupGobrew(t *testing.T, ts *httptest.Server) GoBrew {
func setupGobrew[T testing.TB](t T, ts *httptest.Server) GoBrew {
tags, _ := url.JoinPath(ts.URL, "golang-tags.json")
versionURL, _ := url.JoinPath(ts.URL, "latest")
config := Config{
Expand All @@ -25,6 +25,17 @@ func setupGobrew(t *testing.T, ts *httptest.Server) GoBrew {
return gb
}

func BenchmarkInstallGo(t *testing.B) {
for i := 0; i < t.N; i++ {
ts := httptest.NewServer(http.FileServer(http.Dir("testdata")))
defer ts.Close()
gb := setupGobrew(t, ts)
gb.Install("1.9")
exists := gb.existsVersion("1.9")
assert.Equal(t, true, exists)
}
}

func TestInstallAndExistVersion(t *testing.T) {
t.Parallel()
ts := httptest.NewServer(http.FileServer(http.Dir("testdata")))
Expand Down

0 comments on commit 2feeae8

Please sign in to comment.