Skip to content

Commit

Permalink
feat: add ReadFile method for reading files from docker fs (#423)
Browse files Browse the repository at this point in the history
Expose a ReadFile method on ChainNode so that you can read files from the docker filesystem within test cases that exist in downstream repos.
  • Loading branch information
jtieri committed Mar 13, 2023
1 parent 0d26f66 commit eb9e214
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions chain/cosmos/chain_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,17 @@ func (tn *ChainNode) CopyFile(ctx context.Context, srcPath, dstPath string) erro
return tn.WriteFile(ctx, content, dstPath)
}

// ReadFile reads the contents of a single file at the specified path in the docker filesystem.
// relPath describes the location of the file in the docker volume relative to the home directory.
func (tn *ChainNode) ReadFile(ctx context.Context, relPath string) ([]byte, error) {
fr := dockerutil.NewFileRetriever(tn.logger(), tn.DockerClient, tn.TestName)
gen, err := fr.SingleFileContent(ctx, tn.VolumeName, relPath)
if err != nil {
return nil, fmt.Errorf("failed to read file at %s: %w", relPath, err)
}
return gen, nil
}

// CreateKey creates a key in the keyring backend test for the given node
func (tn *ChainNode) CreateKey(ctx context.Context, name string) error {
tn.lock.Lock()
Expand Down

0 comments on commit eb9e214

Please sign in to comment.