Skip to content

Commit

Permalink
chore: move some code to better handle errors
Browse files Browse the repository at this point in the history
  • Loading branch information
gfyrag committed Oct 24, 2024
1 parent bd0cdee commit cc601f3
Showing 1 changed file with 16 additions and 22 deletions.
38 changes: 16 additions & 22 deletions test/performance/write_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,27 +51,6 @@ func init() {
//go:embed scripts
var scriptsDir embed.FS

// Init default scripts
func init() {
entries, err := scriptsDir.ReadDir("scripts")
if err != nil {
panic(err)
}

for _, entry := range entries {
if entry.IsDir() {
continue
}

script, err := scriptsDir.ReadFile(filepath.Join("scripts", entry.Name()))
if err != nil {
panic(err)
}

scripts[strings.TrimSuffix(entry.Name(), ".js")] = NewJSTransactionProviderFactory(string(script))
}
}

func getHttpClient(authUrl string) *http.Client {
httpClient := &http.Client{
Transport: &http.Transport{
Expand Down Expand Up @@ -110,7 +89,22 @@ func BenchmarkWrite(b *testing.B) {
envFactory = NewRemoteLedgerEnvFactory(getHttpClient(authIssuerURLFlag), ledgerURLFlag)
}

testing.Verbose()
// Load default scripts
if len(scripts) == 0 {
entries, err := scriptsDir.ReadDir("scripts")
require.NoError(b, err)

for _, entry := range entries {
if entry.IsDir() {
continue
}

script, err := scriptsDir.ReadFile(filepath.Join("scripts", entry.Name()))
require.NoError(b, err)

scripts[strings.TrimSuffix(entry.Name(), ".js")] = NewJSTransactionProviderFactory(string(script))
}
}

if envFactory == nil {
b.Errorf("no env selected, you need to specify either --stack.url or --ledger.url\n")
Expand Down

0 comments on commit cc601f3

Please sign in to comment.