-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
Copy pathfiles_test.go
47 lines (38 loc) · 1.03 KB
/
files_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package commands
import (
"context"
"io"
"testing"
dag "github.com/ipfs/boxo/ipld/merkledag"
cmds "github.com/ipfs/go-ipfs-cmds"
coremock "github.com/ipfs/kubo/core/mock"
"github.com/stretchr/testify/require"
)
func TestFilesCp_DagCborNodeFails(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
cmdCtx, err := coremock.MockCmdsCtx()
require.NoError(t, err)
node, err := cmdCtx.ConstructNode()
require.NoError(t, err)
invalidData := []byte{0x00}
protoNode := dag.NodeWithData(invalidData)
err = node.DAG.Add(ctx, protoNode)
require.NoError(t, err)
req := &cmds.Request{
Context: ctx,
Arguments: []string{
"/ipfs/" + protoNode.Cid().String(),
"/test-destination",
},
Options: map[string]interface{}{
"force": false,
},
}
_, pw := io.Pipe()
res, err := cmds.NewWriterResponseEmitter(pw, req)
require.NoError(t, err)
err = filesCpCmd.Run(req, res, &cmdCtx)
require.Error(t, err)
require.ErrorContains(t, err, "cp: source must be a valid UnixFS (dag-pb or raw codec)")
}