Skip to content

Commit

Permalink
chore: add identifier for multiple containers naming
Browse files Browse the repository at this point in the history
  • Loading branch information
RafilxTenfen committed Jul 26, 2024
1 parent c05bd37 commit 5696a72
Showing 1 changed file with 27 additions and 10 deletions.
37 changes: 27 additions & 10 deletions test/e2e/containers/containers.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,27 @@ type Manager struct {
network *dockertest.Network
resources map[string]*dockertest.Resource
isDebugLogEnabled bool
identifier string
}

// NewManager creates a new Manager instance and initializes
// all Docker specific utilities. Returns an error if initialization fails.
func NewManager(networkIdentifier string, isDebugLogEnabled bool, isCosmosRelayer bool) (docker *Manager, err error) {
docker = &Manager{
func NewManager(identifier string, isDebugLogEnabled bool, isCosmosRelayer bool) (m *Manager, err error) {
m = &Manager{
ImageConfig: NewImageConfig(isCosmosRelayer),
resources: make(map[string]*dockertest.Resource),
isDebugLogEnabled: isDebugLogEnabled,
identifier: identifier,
}
docker.pool, err = dockertest.NewPool("")
m.pool, err = dockertest.NewPool("")
if err != nil {
return nil, err
}
docker.network, err = docker.pool.CreateNetwork(fmt.Sprintf("bbn-testnet-%s", networkIdentifier))
m.network, err = m.pool.CreateNetwork(m.NetworkName())
if err != nil {
return nil, err
}
return docker, nil
return m, nil
}

// ExecTxCmd Runs ExecTxCmdWithSuccessString searching for `code: 0`
Expand All @@ -72,7 +74,7 @@ func (m *Manager) ExecTxCmdWithSuccessString(t *testing.T, chainId string, conta

// ExecHermesCmd executes command on the hermes relaer container.
func (m *Manager) ExecHermesCmd(t *testing.T, command []string, success string) (bytes.Buffer, bytes.Buffer, error) {
return m.ExecCmd(t, hermesContainerName, command, success)
return m.ExecCmd(t, m.HermesContainerName(), command, success)
}

// ExecCmd executes command by running it on the node container (specified by containerName)
Expand Down Expand Up @@ -161,7 +163,7 @@ func (m *Manager) ExecCmd(t *testing.T, containerName string, command []string,
func (m *Manager) RunHermesResource(chainAID, osmoARelayerNodeName, osmoAValMnemonic, chainBID, osmoBRelayerNodeName, osmoBValMnemonic string, hermesCfgPath string) (*dockertest.Resource, error) {
hermesResource, err := m.pool.RunWithOptions(
&dockertest.RunOptions{
Name: hermesContainerName,
Name: m.HermesContainerName(),
Repository: m.RelayerRepository,
Tag: m.RelayerTag,
NetworkID: m.network.Network.ID,
Expand Down Expand Up @@ -197,7 +199,7 @@ func (m *Manager) RunHermesResource(chainAID, osmoARelayerNodeName, osmoAValMnem
if err != nil {
return nil, err
}
m.resources[hermesContainerName] = hermesResource
m.resources[m.HermesContainerName()] = hermesResource
return hermesResource, nil
}

Expand All @@ -206,7 +208,7 @@ func (m *Manager) RunHermesResource(chainAID, osmoARelayerNodeName, osmoAValMnem
func (m *Manager) RunRlyResource(chainAID, osmoARelayerNodeName, osmoAValMnemonic, chainAIbcPort, chainBID, osmoBRelayerNodeName, osmoBValMnemonic, chainBIbcPort string, rlyCfgPath string) (*dockertest.Resource, error) {
rlyResource, err := m.pool.RunWithOptions(
&dockertest.RunOptions{
Name: cosmosRelayerContainerName,
Name: m.RelayerContainerName(),
Repository: m.RelayerRepository,
Tag: m.RelayerTag,
NetworkID: m.network.Network.ID,
Expand Down Expand Up @@ -238,7 +240,7 @@ func (m *Manager) RunRlyResource(chainAID, osmoARelayerNodeName, osmoAValMnemoni
if err != nil {
return nil, err
}
m.resources[cosmosRelayerContainerName] = rlyResource
m.resources[m.RelayerContainerName()] = rlyResource
return rlyResource, nil
}

Expand Down Expand Up @@ -340,3 +342,18 @@ func noRestart(config *docker.HostConfig) {
Name: "no",
}
}

// RelayerContainerName returns the relayer container name with identifier of the manager.
func (m *Manager) RelayerContainerName() string {
return fmt.Sprintf("%s-%s", cosmosRelayerContainerName, m.identifier)
}

// HermesContainerName returns the hermes relayer container name with identifier of the manager.
func (m *Manager) HermesContainerName() string {
return fmt.Sprintf("%s-%s", hermesContainerName, m.identifier)
}

// NetworkName returns the network name with identifier of the manager.
func (m *Manager) NetworkName() string {
return fmt.Sprintf("bbn-testnet-%s", m.identifier)
}

0 comments on commit 5696a72

Please sign in to comment.