Skip to content

Commit 98ba3e1

Browse files
Shivaji KharseShivaji Kharse
authored andcommitted
add tests
1 parent 3bbc90a commit 98ba3e1

4 files changed

Lines changed: 412 additions & 4 deletions

File tree

dgraphtest/local_cluster.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1397,6 +1397,27 @@ func (c *LocalCluster) GetAlphaGrpcEndpoint(id int) (string, error) {
13971397

13981398
// CopyExportToHost copies exported files from the container to a host directory.
13991399
// It returns the paths to RDF/JSON files and schema files on the host.
1400+
func (c *LocalCluster) ReadFileFromContainer(containerPath string) ([]byte, error) {
1401+
ctx, cancel := context.WithTimeout(context.Background(), requestTimeout)
1402+
defer cancel()
1403+
1404+
ts, _, err := c.dcli.CopyFromContainer(ctx, c.alphas[0].cid(), containerPath)
1405+
if err != nil {
1406+
return nil, errors.Wrapf(err, "error copying file from container [%v]", c.alphas[0].cname())
1407+
}
1408+
defer ts.Close()
1409+
1410+
tr := tar.NewReader(ts)
1411+
if _, err := tr.Next(); err != nil {
1412+
return nil, errors.Wrap(err, "error reading tar header")
1413+
}
1414+
data, err := io.ReadAll(tr)
1415+
if err != nil {
1416+
return nil, errors.Wrap(err, "error reading file contents from tar stream")
1417+
}
1418+
return data, nil
1419+
}
1420+
14001421
func (c *LocalCluster) CopyExportToHost(exportDir, hostDir string) (dataFiles, schemaFiles []string, err error) {
14011422
ctx, cancel := context.WithTimeout(context.Background(), requestTimeout)
14021423
defer cancel()

0 commit comments

Comments
 (0)