From 2feeae89cba506683bbb1d43c32f3bd3086695da Mon Sep 17 00:00:00 2001 From: Pulkit Kathuria Date: Sat, 6 Apr 2024 19:15:44 +0900 Subject: [PATCH] (feat) added benchmarks for a simple Go installation --- .github/workflows/coveritup.yml | 7 +++++++ gobrew_test.go | 13 ++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/.github/workflows/coveritup.yml b/.github/workflows/coveritup.yml index fb91144..07992a3 100644 --- a/.github/workflows/coveritup.yml +++ b/.github/workflows/coveritup.yml @@ -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 diff --git a/gobrew_test.go b/gobrew_test.go index 6b01ecd..424e127 100644 --- a/gobrew_test.go +++ b/gobrew_test.go @@ -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{ @@ -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")))