Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(e2e): parse go mod for babylond version #67

Merged
merged 1 commit into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
Loading