Skip to content

Commit

Permalink
Simplify getVersionInfo test and remove rage condition
Browse files Browse the repository at this point in the history
  • Loading branch information
2opremio committed Jun 14, 2024
1 parent 5e1e7fc commit 6d88a73
Showing 1 changed file with 10 additions and 42 deletions.
52 changes: 10 additions & 42 deletions cmd/soroban-rpc/internal/integrationtest/get_version_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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")
}

0 comments on commit 6d88a73

Please sign in to comment.