kubo/core/commands/files_test.go
rifeplight 3f2cc50eb8
Some checks failed
CodeQL / codeql (push) Waiting to run
Docker Check / lint (push) Waiting to run
Docker Check / build (push) Waiting to run
Gateway Conformance / gateway-conformance (push) Waiting to run
Gateway Conformance / gateway-conformance-libp2p-experiment (push) Waiting to run
Go Build / go-build (push) Waiting to run
Go Check / go-check (push) Waiting to run
Go Lint / go-lint (push) Waiting to run
Go Test / go-test (push) Waiting to run
Interop / interop-prep (push) Waiting to run
Interop / helia-interop (push) Blocked by required conditions
Interop / ipfs-webui (push) Blocked by required conditions
Sharness / sharness-test (push) Waiting to run
Spell Check / spellcheck (push) Waiting to run
Migrations / test (macos-latest) (push) Has been cancelled
Migrations / test (ubuntu-latest) (push) Has been cancelled
Migrations / test (windows-latest) (push) Has been cancelled
refactor: replace context.WithCancel with t.Context (#11083)
Signed-off-by: rifeplight <rifeplight@outlook.com>
2025-11-28 16:39:55 +01:00

46 lines
992 B
Go

package commands
import (
"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 := t.Context()
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)")
}