Skip to content

Commit

Permalink
chore(e2e): parse go mod for babylond version (#67)
Browse files Browse the repository at this point in the history
Ensures that our e2e tests version use a correct version of babylond
from go.mod
  • Loading branch information
Lazar955 authored Sep 25, 2024
1 parent 934e142 commit 627a8d0
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 6 deletions.
13 changes: 10 additions & 3 deletions itest/container/config.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
package container

import (
"github.com/babylonlabs-io/finality-provider/testutil"
"github.com/stretchr/testify/require"
"testing"
)

// ImageConfig contains all images and their respective tags
// needed for running e2e tests.
type ImageConfig struct {
Expand All @@ -10,13 +16,14 @@ type ImageConfig struct {
//nolint:deadcode
const (
dockerBabylondRepository = "babylonlabs/babylond"
dockerBabylondVersionTag = "v0.10.0"
)

// NewImageConfig returns ImageConfig needed for running e2e test.
func NewImageConfig() ImageConfig {
func NewImageConfig(t *testing.T) ImageConfig {
babylondVersion, err := testutil.GetBabylonVersion()
require.NoError(t, err)
return ImageConfig{
BabylonRepository: dockerBabylondRepository,
BabylonVersion: dockerBabylondVersionTag,
BabylonVersion: babylondVersion,
}
}
4 changes: 2 additions & 2 deletions itest/container/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ type Manager struct {

// NewManager creates a new ContainerManager instance and initializes
// all Docker specific utilities. Returns an error if initialization fails.
func NewManager() (docker *Manager, err error) {
func NewManager(t *testing.T) (docker *Manager, err error) {
docker = &Manager{
cfg: NewImageConfig(),
cfg: NewImageConfig(t),
resources: make(map[string]*dockertest.Resource),
}
docker.pool, err = dockertest.NewPool("")
Expand Down
2 changes: 1 addition & 1 deletion itest/test_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ type TestDelegationData struct {
}

func StartManager(t *testing.T) *TestManager {
manager, err := container.NewManager()
manager, err := container.NewManager(t)
require.NoError(t, err)
testDir, err := tempDir(t, "fp-e2e-test-*")
require.NoError(t, err)
Expand Down
32 changes: 32 additions & 0 deletions testutil/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package testutil

import (
"fmt"
"golang.org/x/mod/modfile"
"os"
"path/filepath"
)

// GetBabylonVersion returns babylond version from go.mod
func GetBabylonVersion() (string, error) {
goModPath := filepath.Join("..", "go.mod")
data, err := os.ReadFile(goModPath)
if err != nil {
return "", err
}

// Parse the go.mod file
modFile, err := modfile.Parse("go.mod", data, nil)
if err != nil {
return "", err
}

const modName = "github.com/babylonlabs-io/babylon"
for _, require := range modFile.Require {
if require.Mod.Path == modName {
return require.Mod.Version, nil
}
}

return "", fmt.Errorf("module %s not found", modName)
}

0 comments on commit 627a8d0

Please sign in to comment.