1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-05-22 01:17:11 +08:00
Files
kubo/core/commands/get_test.go
Steven Allen 76e1da02a8 gx: massive update
Note: This commit is technically broken. However, I need to make a bunch of
cmds changes to make this work and I'd rather not bundle both changes into a
single commit.

License: MIT
Signed-off-by: Steven Allen <steven@stebalien.com>
2017-11-20 22:20:27 -08:00

62 lines
1.5 KiB
Go

package commands
import (
"testing"
"gx/ipfs/QmQtQuaQvS5mKJVoCvL5FvrYH7oZPjxsVHf2bKSGgcVmZt/go-ipfs-cmds"
"gx/ipfs/QmUyfy4QSr3NXym4etEiRyxBLqqAeKHJuRdi8AACxg63fZ/go-ipfs-cmdkit"
)
func TestGetOutputPath(t *testing.T) {
cases := []struct {
args []string
opts cmdkit.OptMap
outPath string
}{
{
args: []string{"/ipns/multiformats.io/"},
opts: map[string]interface{}{
"output": "takes-precedence",
},
outPath: "takes-precedence",
},
{
args: []string{"/ipns/multiformats.io/", "some-other-arg-to-be-ignored"},
opts: cmdkit.OptMap{
"output": "takes-precedence",
},
outPath: "takes-precedence",
},
{
args: []string{"/ipns/multiformats.io/"},
outPath: "multiformats.io",
opts: cmdkit.OptMap{},
},
{
args: []string{"/ipns/multiformats.io/logo.svg/"},
outPath: "logo.svg",
opts: cmdkit.OptMap{},
},
{
args: []string{"/ipns/multiformats.io", "some-other-arg-to-be-ignored"},
outPath: "multiformats.io",
opts: cmdkit.OptMap{},
},
}
defOpts, err := GetCmd.GetOptions([]string{})
if err != nil {
t.Fatalf("error getting default command options: %v", err)
}
for _, tc := range cases {
req, err := cmds.NewRequest([]string{}, tc.opts, tc.args, nil, GetCmd, defOpts)
if err != nil {
t.Fatalf("error creating a command request: %v", err)
}
if outPath := getOutPath(req); outPath != tc.outPath {
t.Errorf("expected outPath %s to be %s", outPath, tc.outPath)
}
}
}