Skip to content

Commit

Permalink
Fix macos unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
marun committed Nov 27, 2023
1 parent a72fae4 commit 931b4f2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
29 changes: 19 additions & 10 deletions tests/fixture/testnet/local/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,24 @@ type LocalNetwork struct {
Dir string
}

func NewLocalNetwork(dir string) (*LocalNetwork, error) {
// Ensure a real and absolute network dir so that node
// configuration that embeds the network path will continue to
// work regardless of symlink and working directory changes.
absDir, err := filepath.Abs(dir)
if err != nil {
return nil, err
}
realDir, err := filepath.EvalSymlinks(absDir)
if err != nil {
return nil, err
}

return &LocalNetwork{
Dir: realDir,
}, nil
}

// Returns the configuration of the network in backend-agnostic form.
func (ln *LocalNetwork) GetConfig() testnet.NetworkConfig {
return ln.NetworkConfig
Expand Down Expand Up @@ -208,19 +226,10 @@ func StartNetwork(

// Read a network from the provided directory.
func ReadNetwork(dir string) (*LocalNetwork, error) {
// Ensure a real and absolute network dir so that node
// configuration that embeds the network path will continue to
// work regardless of symlink and working directory changes.
absDir, err := filepath.Abs(dir)
network, err := NewLocalNetwork(dir)
if err != nil {
return nil, err
}
realDir, err := filepath.EvalSymlinks(absDir)
if err != nil {
return nil, err
}

network := &LocalNetwork{Dir: realDir}
if err := network.ReadAll(); err != nil {
return nil, fmt.Errorf("failed to read local network: %w", err)
}
Expand Down
3 changes: 2 additions & 1 deletion tests/fixture/testnet/local/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ func TestNetworkSerialization(t *testing.T) {

tmpDir := t.TempDir()

network := &LocalNetwork{Dir: tmpDir}
network, err := NewLocalNetwork(tmpDir)
require.NoError(err)
require.NoError(network.PopulateLocalNetworkConfig(1337, 1, 1))
require.NoError(network.WriteAll())

Expand Down

0 comments on commit 931b4f2

Please sign in to comment.