Skip to content

Commit

Permalink
releases: Add benchmark for ExectVersion.Install() (#134)
Browse files Browse the repository at this point in the history
  • Loading branch information
radeksimko committed May 11, 2023
1 parent 858962c commit cb65e67
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
2 changes: 1 addition & 1 deletion internal/testutil/test_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"testing"
)

func NewTestServer(t *testing.T, mockDir string) *httptest.Server {
func NewTestServer(t testing.TB, mockDir string) *httptest.Server {
t.Helper()

mux := http.NewServeMux()
Expand Down
30 changes: 29 additions & 1 deletion releases/releases_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package releases

import (
"context"
"fmt"
"io/ioutil"
"os"
"path/filepath"
Expand Down Expand Up @@ -153,7 +154,34 @@ func TestExactVersion(t *testing.T) {
}
}

func getTestPubKey(t *testing.T) string {
func BenchmarkExactVersion(b *testing.B) {
mockApiRoot := filepath.Join("testdata", "mock_api_tf_0_14_with_prereleases")

for i := 0; i < b.N; i++ {
installDir, err := ioutil.TempDir("", fmt.Sprintf("%s_%d", "terraform", i))
if err != nil {
b.Fatal(err)
}

ev := &ExactVersion{
Product: product.Terraform,
Version: version.Must(version.NewVersion("0.14.11")),
ArmoredPublicKey: getTestPubKey(b),
apiBaseURL: testutil.NewTestServer(b, mockApiRoot).URL,
InstallDir: installDir,
}
ev.SetLogger(testutil.TestLogger())

ctx := context.Background()
_, err = ev.Install(ctx)
if err != nil {
b.Fatal(err)
}
b.Cleanup(func() { ev.Remove(ctx) })
}
}

func getTestPubKey(t testing.TB) string {
f, err := os.Open(filepath.Join("testdata", "2FCA0A85.pub"))
b, err := ioutil.ReadAll(f)
if err != nil {
Expand Down

0 comments on commit cb65e67

Please sign in to comment.