From 6d88a73762e2929981c5e3a457f9f0e475d49fe7 Mon Sep 17 00:00:00 2001 From: Alfonso Acosta Date: Fri, 14 Jun 2024 15:28:05 +0200 Subject: [PATCH] Simplify getVersionInfo test and remove rage condition --- .../integrationtest/get_version_info_test.go | 52 ++++--------------- 1 file changed, 10 insertions(+), 42 deletions(-) diff --git a/cmd/soroban-rpc/internal/integrationtest/get_version_info_test.go b/cmd/soroban-rpc/internal/integrationtest/get_version_info_test.go index c7ebf413..b1bdb858 100644 --- a/cmd/soroban-rpc/internal/integrationtest/get_version_info_test.go +++ b/cmd/soroban-rpc/internal/integrationtest/get_version_info_test.go @@ -2,12 +2,8 @@ package integrationtest import ( "context" - "fmt" - "os/exec" "testing" - "github.com/stretchr/testify/require" - "github.com/stellar/soroban-rpc/cmd/soroban-rpc/internal/config" "github.com/stellar/soroban-rpc/cmd/soroban-rpc/internal/integrationtest/infrastructure" @@ -16,50 +12,22 @@ import ( "github.com/stellar/soroban-rpc/cmd/soroban-rpc/internal/methods" ) +func init() { + // Initialize variables to non-empty values + config.CommitHash = "commitHash" + config.BuildTimestamp = "buildTimestamp" +} + func TestGetVersionInfoSucceeds(t *testing.T) { test := infrastructure.NewTest(t, nil) - version, commitHash, buildTimeStamp := config.Version, config.CommitHash, config.BuildTimestamp - - populateVersionInfo(t) - - // reset to previous config values - t.Cleanup(func() { - config.Version = version - config.CommitHash = commitHash - config.BuildTimestamp = buildTimeStamp - }) - - client := test.GetRPCLient() - var result methods.GetVersionInfoResponse - err := client.CallResult(context.Background(), "getVersionInfo", nil, &result) + err := test.GetRPCLient().CallResult(context.Background(), "getVersionInfo", nil, &result) assert.NoError(t, err) - assert.Equal(t, config.Version, result.Version) - assert.Equal(t, config.BuildTimestamp, result.BuildTimestamp) - assert.Equal(t, config.CommitHash, result.CommitHash) + assert.Equal(t, "0.0.0", result.Version) + assert.Equal(t, "buildTimestamp", result.BuildTimestamp) + assert.Equal(t, "commitHash", result.CommitHash) assert.Equal(t, test.GetProtocolVersion(), result.ProtocolVersion) assert.NotEmpty(t, result.CaptiveCoreVersion) - -} - -// Runs git commands to fetch version information -func populateVersionInfo(t *testing.T) { - - execFunction := func(command string, args ...string) string { - cmd := exec.Command(command, args...) - t.Log("Running", cmd.Env, cmd.Args) - out, innerErr := cmd.Output() - if exitErr, ok := innerErr.(*exec.ExitError); ok { - fmt.Printf("stdout:\n%s\n", string(out)) - fmt.Printf("stderr:\n%s\n", string(exitErr.Stderr)) - } - require.NoError(t, innerErr) - return string(out) - } - - config.Version = execFunction("git", "describe", "--tags", "--always", "--abbrev=0", "--match='v[0-9]*.[0-9]*.[0-9]*'") - config.CommitHash = execFunction("git", "rev-parse", "HEAD") - config.BuildTimestamp = execFunction("date", "+%Y-%m-%dT%H:%M:%S") }